merge conflict resolved

This commit is contained in:
maliakal_d 2018-10-30 14:31:20 +01:00
commit 70a1b87603
17 changed files with 4688 additions and 4958 deletions

2
.clang-format Normal file
View File

@ -0,0 +1,2 @@
BasedOnStyle: LLVM
IndentWidth: 4

View File

@ -14,8 +14,8 @@ else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 ")
endif ()
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread")
find_package(Qt4)
find_package(Qwt 6)

File diff suppressed because it is too large Load Diff

View File

@ -2,41 +2,44 @@
#define MULTI_SLS_DETECTOR_H
/**
@libdoc The multiSlsDetector class is used to operate several slsDetectors in parallel.
@libdoc The multiSlsDetector class is used to operate several slsDetectors in
parallel.
* @short This is the base class for multi detector system functionalities
* @author Anna Bergamaschi
*/
#include "sls_detector_defs.h"
#include "error_defs.h"
#include "logger.h"
class slsDetector;
class SharedMemory;
class ZmqSocket;
class detectorData;
#include <memory>
#include <vector>
#include <string>
#include <mutex>
#include <semaphore.h>
#include <string>
#include <thread>
#include <vector>
#define MULTI_SHMVERSION 0x181002
#define SHORT_STRING_LENGTH 50
#define DATE_LENGTH 30
class multiSlsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
class multiSlsDetector : public virtual slsDetectorDefs,
public virtual errorDefs {
private:
/**
* @short structure allocated in shared memory to store detector settings for IPC and cache
* @short structure allocated in shared memory to store detector settings
* for IPC and cache
*/
typedef struct sharedMultiSlsDetector {
/* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND ------*/
/* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND
* ------*/
/** shared memory version */
int shmversion;
@ -53,10 +56,8 @@ private:
/** number of sls detectors in shared memory */
int numberOfDetectors;
/** END OF FIXED PATTERN -----------------------------------------------*/
/** END OF FIXED PATTERN
* -----------------------------------------------*/
/** Number of detectors operated at once */
int numberOfDetector[2];
@ -101,10 +102,6 @@ private:
/** timer values */
int64_t timerValue[MAX_TIMERS];
/** threaded processing flag (i.e. if data are processed and written to
* file in a separate thread) */
int threadedProcessing;
/** flag for acquiring */
bool acquiringFlag;
@ -117,16 +114,12 @@ private:
} sharedMultiSlsDetector;
public:
/**
* Constructor
* @param id multi detector id
* @param verify true to verify if shared memory version matches existing one
* @param verify true to verify if shared memory version matches existing
* one
* @param update true to update last user pid, date etc
*/
multiSlsDetector(int id = 0, bool verify = true, bool update = true);
@ -139,7 +132,8 @@ public:
/**
* Creates/open shared memory, initializes detector structure and members
* Called by constructor/ set hostname / read config file
* @param verify true to verify if shared memory version matches existing one
* @param verify true to verify if shared memory version matches existing
* one
* @param update true to update last user pid, date etc
*/
void setupMultiDetector(bool verify = true, bool update = true);
@ -156,16 +150,19 @@ public:
* and return a vector of results
*/
template <typename RT, typename... CT>
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...), CT... Args);
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...),
CT... Args);
/**
* If specific position, then provide result with that detector at position pos
* else concatenate the result of all detectors
* If specific position, then provide result with that detector at position
* pos else concatenate the result of all detectors
* @param somefunc function pointer
* @param pos positin of detector in array (-1 is for all)
* @returns result for detector at that position or concatenated string of all detectors
* @returns result for detector at that position or concatenated string of
* all detectors
*/
// std::string concatResultOrPos(std::string (slsDetector::*somefunc)(int), int pos);
// std::string concatResultOrPos(std::string (slsDetector::*somefunc)(int),
// int pos);
/**
* Decodes which detector and the corresponding channel numbers for it
@ -234,21 +231,6 @@ public:
*/
int64_t getId(idMode mode, int detPos = -1);
/**
* Get sls detector object from position in detectors array
* @param detPos -1 for all detectors in list or specific detector position
* @returns pointer to sls detector object
*/
// slsDetector* getSlsDetector(int detPos = -1);
/**
* Accessing the sls detector from the multi list using position
* @param detPos -1 for all detectors in list or specific detector position
* @returns slsDetector object
*/
// slsDetector *operator()(int detPos = -1) const;
// slsDetector* operator[](int detPos) const;
/**
* Free shared memory from the command line
* avoiding creating the constructor classes and mapping
@ -284,23 +266,25 @@ public:
* Gets the hostname of detector at particular position
* or concatenated hostnames of all the sls detectors
* @param detPos -1 for all detectors in list or specific detector position
* @returns concatenated hostnames of all detectors or hostname of specific one
* @returns concatenated hostnames of all detectors or hostname of specific
* one
*/
std::string getHostname(int detPos = -1);
/**
* Appends detectors to the end of the list in shared memory
* Connects to them to set up online flag
* @param name concatenated hostname of the sls detectors to be appended to the list
* @param name concatenated hostname of the sls detectors to be appended to
* the list
*/
void addMultipleDetectors(const char *name);
using slsDetectorDefs::getDetectorType;
/**
* Get Detector type for a particular sls detector or get the first one
* @param detPos -1 for all detectors in list or specific detector position
* @returns detector type of sls detector in position pos, if -1, returns the first det type
* @returns detector type of sls detector in position pos, if -1, returns
* the first det type
*/
detectorType getDetectorsType(int detPos = -1);
@ -308,14 +292,16 @@ public:
* Concatenates string types of all sls detectors or
* returns the detector type of the first sls detector
* @param detPos -1 for all detectors in list or specific detector position
* @returns detector type of sls detector in position pos, if -1, concatenates
* @returns detector type of sls detector in position pos, if -1,
* concatenates
*/
std::string sgetDetectorsType(int detPos = -1);
/**
* Gets Detector type (concatenates if different)
* @param detPos -1 for all detectors in list or specific detector position
* @returns detector type of sls detector in position pos, if -1, concatenates
* @returns detector type of sls detector in position pos, if -1,
* concatenates
*/
std::string getDetectorType(int detPos = -1);
@ -340,7 +326,8 @@ public:
void getNumberOfDetectors(int &nx, int &ny);
/**
* Returns the total number of channels of all sls detectors from shared memory
* Returns the total number of channels of all sls detectors from shared
* memory
* @param detPos -1 for all detectors in list or specific detector position
* @returns the total number of channels of all sls detectors
*/
@ -366,21 +353,23 @@ public:
int getTotalNumberOfChannelsInclGapPixels(dimension d, int detPos = -1);
/**
* Returns the maximum number of channels of all sls detectors in each dimension d
* from shared memory. multi detector shared memory variable to calculate
* offsets for each sls detector
* Returns the maximum number of channels of all sls detectors in each
* dimension d from shared memory. multi detector shared memory variable to
* calculate offsets for each sls detector
* @param d dimension d
* @returns the maximum number of channels of all sls detectors in dimension d
* @returns the maximum number of channels of all sls detectors in dimension
* d
*/
int getMaxNumberOfChannelsPerDetector(dimension d);
/**
* Sets the maximum number of channels of all sls detectors in each dimension d
* from shared memory, multi detector shared memory variable to calculate
* offsets for each sls detector
* Sets the maximum number of channels of all sls detectors in each
* dimension d from shared memory, multi detector shared memory variable to
* calculate offsets for each sls detector
* @param d dimension d
* @param i maximum number of channels for multi structure in dimension d
* @returns the maximum number of channels of all sls detectors in dimension d
* @returns the maximum number of channels of all sls detectors in dimension
* d
*/
int setMaxNumberOfChannelsPerDetector(dimension d, int i);
@ -388,7 +377,8 @@ public:
* Get Detector offset from shared memory in dimension d
* @param d dimension d
* @param detPos -1 for all detectors in list or specific detector position
* @returns offset in dimension d, -1 if pos is not an actual position in list
* @returns offset in dimension d, -1 if pos is not an actual position in
* list
*/
int getDetectorOffset(dimension d, int detPos = -1);
@ -401,8 +391,8 @@ public:
void setDetectorOffset(dimension d, int off, int detPos = -1);
/**
* Updates the channel offsets in X and Y dimension for all the sls detectors
* It is required for decodeNMod and setting ROI
* Updates the channel offsets in X and Y dimension for all the sls
* detectors It is required for decodeNMod and setting ROI
*/
void updateOffsets();
@ -410,8 +400,10 @@ public:
* Checks if the multi detectors are online and sets the online flag
* @param online if GET_ONLINE_FLAG, only returns shared memory online flag,
* else sets the detector in online/offline state
* if OFFLINE_FLAG, (i.e. no communication to the detector - using only local structure - no data acquisition possible!);
* if ONLINE_FLAG, detector in online state (i.e. communication to the detector updating the local structure)
* if OFFLINE_FLAG, (i.e. no communication to the detector - using only
* local structure - no data acquisition possible!); if ONLINE_FLAG,
* detector in online state (i.e. communication to the detector updating the
* local structure)
* @param detPos -1 for all detectors in list or specific detector position
* @returns online/offline status
*/
@ -493,9 +485,9 @@ public:
detectorSettings getSettings(int detPos = -1);
/**
* Load detector settings from the settings file picked from the trimdir/settingsdir
* Eiger only stores in shared memory ( a get will overwrite this)
* For Eiger, one must use threshold
* Load detector settings from the settings file picked from the
* trimdir/settingsdir Eiger only stores in shared memory ( a get will
* overwrite this) For Eiger, one must use threshold
* @param isettings settings
* @param detPos -1 for all detectors in list or specific detector position
* @returns current settings
@ -517,7 +509,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns current threshold value for imod in ev (-1 failed)
*/
int setThresholdEnergy(int e_eV, detectorSettings isettings=GET_SETTINGS,int tb=1, int detPos = -1);
int setThresholdEnergy(int e_eV, detectorSettings isettings = GET_SETTINGS,
int tb = 1, int detPos = -1);
/**
* Returns the detector trimbit/settings directory \sa sharedSlsDetector
@ -588,14 +581,16 @@ public:
int sendSoftwareTrigger(int detPos = -1);
/**
* Start detector acquisition and read all data (Blocking until end of acquisition)
* Start detector acquisition and read all data (Blocking until end of
* acquisition)
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int startAndReadAll(int detPos = -1);
/**
* Start readout (without exposure or interrupting exposure) (Eiger store in ram)
* Start readout (without exposure or interrupting exposure) (Eiger store in
* ram)
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
@ -620,7 +615,8 @@ public:
* @param index timer index
* @param t time in ns or number of...(e.g. frames, gates, probes)
* @param detPos -1 for all detectors in list or specific detector position
* @returns timer set value in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates,
* probes)
*/
int64_t setTimer(timerIndex index, int64_t t = -1, int detPos = -1);
@ -631,7 +627,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns exposure time in ns, or s if specified
*/
double setExposureTime(double t = -1, bool inseconds = false, int detPos = -1);
double setExposureTime(double t = -1, bool inseconds = false,
int detPos = -1);
/**
* Set/get exposure period
@ -640,7 +637,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns exposure period in ns, or s if specified
*/
double setExposurePeriod(double t = -1, bool inseconds = false, int detPos = -1);
double setExposurePeriod(double t = -1, bool inseconds = false,
int detPos = -1);
/**
* Set/get delay after trigger (Gotthard, Jungfrau(not for this release))
@ -649,7 +647,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns delay after trigger in ns, or s if specified
*/
double setDelayAfterTrigger(double t = -1, bool inseconds = false, int detPos = -1);
double setDelayAfterTrigger(double t = -1, bool inseconds = false,
int detPos = -1);
/**
* (Advanced users)
@ -659,7 +658,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns sub frame exposure time in ns, or s if specified
*/
double setSubFrameExposureTime(double t = -1, bool inseconds = false, int detPos = -1);
double setSubFrameExposureTime(double t = -1, bool inseconds = false,
int detPos = -1);
/**
* (Advanced users)
@ -669,7 +669,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns sub frame dead time in ns, or s if specified
*/
double setSubFrameExposureDeadTime(double t = -1, bool inseconds = false, int detPos = -1);
double setSubFrameExposureDeadTime(double t = -1, bool inseconds = false,
int detPos = -1);
/**
* Set/get number of frames
@ -722,18 +723,22 @@ public:
double getMeasuredSubFramePeriod(bool inseconds = false, int detPos = -1);
/**
* Set/get timer value left in acquisition (not all implemented for all detectors)
* Set/get timer value left in acquisition (not all implemented for all
* detectors)
* @param index timer index
* @param t time in ns or number of...(e.g. frames, gates, probes)
* @param detPos -1 for all detectors in list or specific detector position
* @returns timer set value in ns or number of...(e.g. frames, gates, probes)
* @returns timer set value in ns or number of...(e.g. frames, gates,
* probes)
*/
int64_t getTimeLeft(timerIndex index, int detPos = -1);
/**
* Set speed
* @param sp speed type (clkdivider option for Jungfrau and Eiger, others for Mythen/Gotthard)
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual
* @param sp speed type (clkdivider option for Jungfrau and Eiger, others
* for Mythen/Gotthard)
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other
* values check manual
* @param detPos -1 for all detectors in list or specific detector position
* @returns value of speed set
*/
@ -741,7 +746,8 @@ public:
/**
* Set/get dynamic range and updates the number of dataBytes
* (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to 1)
* (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to
* 1)
* @param i dynamic range (-1 get)
* @param detPos -1 for all detectors in list or specific detector position
* @returns current dynamic range
@ -770,7 +776,8 @@ public:
* Get adc value
* @param index adc(DAC) index
* @param detPos -1 for all detectors in list or specific detector position
* @returns current adc value (temperature for eiger and jungfrau in millidegrees)
* @returns current adc value (temperature for eiger and jungfrau in
* millidegrees)
*/
int getADC(dacIndex index, int detPos = -1);
@ -780,20 +787,26 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns current timing mode
*/
externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE, int detPos = -1);
externalCommunicationMode setExternalCommunicationMode(
externalCommunicationMode pol = GET_EXTERNAL_COMMUNICATION_MODE,
int detPos = -1);
/**
* Set/get external signal flags (to specify triggerinrising edge etc) (Gotthard, Mythen)
* Set/get external signal flags (to specify triggerinrising edge etc)
* (Gotthard, Mythen)
* @param pol external signal flag (-1 gets)
* @param signalindex singal index (0 - 3)
* @param detPos -1 for all detectors in list or specific detector position
* @returns current timing mode
*/
externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0, int detPos = -1);
externalSignalFlag
setExternalSignalFlags(externalSignalFlag pol = GET_EXTERNAL_SIGNAL_FLAG,
int signalindex = 0, int detPos = -1);
/**
* Set/get readout flags (Eiger, Mythen)
* @param flag readout flag (Eiger options: parallel, nonparallel, safe etc.) (-1 gets)
* @param flag readout flag (Eiger options: parallel, nonparallel, safe
* etc.) (-1 gets)
* @param detPos -1 for all detectors in list or specific detector position
* @returns readout flag
*/
@ -856,7 +869,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns network parameter value set (from getNetworkParameter)
*/
std::string setNetworkParameter(networkParameter parameter, std::string value, int detPos = -1);
std::string setNetworkParameter(networkParameter parameter,
std::string value, int detPos = -1);
/**
* Get network parameter
@ -870,9 +884,11 @@ public:
* (advanced users)
* Set/Get receiver streaming out ZMQ port and restarts receiver sockets
* @param i sets, -1 gets
* If detPos is -1(multi module), port calculated (increments) for all the individual detectors using i
* If detPos is -1(multi module), port calculated (increments) for all the
* individual detectors using i
* @param detPos -1 for all detectors in list or specific detector position
* @returns receiver streaming out ZMQ port (if multiple, of first receiver socket)
* @returns receiver streaming out ZMQ port (if multiple, of first receiver
* socket)
*/
int setReceiverDataStreamingOutPort(int i = -1, int detPos = -1);
@ -880,9 +896,11 @@ public:
* (advanced users)
* Set/Get client streaming in ZMQ port and restarts client sockets
* @param i sets, -1 gets
* If detPos is -1(multi module), port calculated (increments) for all the individual detectors using i
* If detPos is -1(multi module), port calculated (increments) for all the
* individual detectors using i
* @param detPos -1 for all detectors in list or specific detector position
* @returns receiver streaming out ZMQ port (if multiple, of first receiver socket)
* @returns receiver streaming out ZMQ port (if multiple, of first receiver
* socket)
*/
int setClientDataStreamingInPort(int i = -1, int detPos = -1);
@ -894,7 +912,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns receiver streaming out ZMQ IP
*/
std::string setReceiverDataStreamingOutIP(std::string ip="", int detPos = -1);
std::string setReceiverDataStreamingOutIP(std::string ip = "",
int detPos = -1);
/**
* (advanced users)
@ -904,7 +923,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns client streaming in ZMQ IP
*/
std::string setClientDataStreamingInIP(std::string ip="", int detPos = -1);
std::string setClientDataStreamingInIP(std::string ip = "",
int detPos = -1);
/**
* Set 10GbE Flow Control (Eiger)
@ -930,7 +950,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int loadImageToDetector(imageType index, const std::string& fname, int detPos = -1);
int loadImageToDetector(imageType index, const std::string &fname,
int detPos = -1);
/**
* Writes the counter memory block from the detector (Gotthard)
@ -939,7 +960,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int writeCounterBlockFile(const std::string& fname,int startACQ=0, int detPos = -1);
int writeCounterBlockFile(const std::string &fname, int startACQ = 0,
int detPos = -1);
/**
* Resets counter in detector (Gotthard)
@ -951,7 +973,8 @@ public:
/**
* Set/get counter bit in detector (Gotthard)
* @param i is -1 to get, 0 to reset and any other value to set the counter bit
* @param i is -1 to get, 0 to reset and any other value to set the counter
* bit
* @param detPos -1 for all detectors in list or specific detector position
* @returns the counter bit in detector
*/
@ -975,7 +998,8 @@ public:
int setROI(int n = -1, ROI roiLimits[] = NULL, int detPos = -1);
/**
* Get ROI from each detector and convert it to the multi detector scale (Gotthard)
* Get ROI from each detector and convert it to the multi detector scale
* (Gotthard)
* @param n number of rois
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
@ -983,7 +1007,8 @@ public:
ROI *getROI(int &n, int detPos = -1);
/**
* Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert users
* Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert
* users
* @param addr address of adc register
* @param val value
* @param detPos -1 for all detectors in list or specific detector position
@ -1001,9 +1026,11 @@ public:
/**
* Set deactivated Receiver padding mode (Eiger only)
* @param padding padding option for deactivated receiver. Can be 1 (padding), 0 (no padding), -1 (gets)
* @param padding padding option for deactivated receiver. Can be 1
* (padding), 0 (no padding), -1 (gets)
* @param detPos -1 for all detectors in list or specific detector position
* @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for padding option
* @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for
* padding option
*/
int setDeactivatedRxrPaddingMode(int padding = -1, int detPos = -1);
@ -1273,7 +1300,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns frames discard policy set in receiver
*/
frameDiscardPolicy setReceiverFramesDiscardPolicy(frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY, int detPos = -1);
frameDiscardPolicy setReceiverFramesDiscardPolicy(
frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY, int detPos = -1);
/**
* Sets the partial frames padding enable in receiver
@ -1395,7 +1423,8 @@ public:
/**
* (previously setReadReceiverFrequency)
* Sets the receiver streaming frequency
* @param freq nth frame streamed out, if 0, streamed out at a timer of 200 ms
* @param freq nth frame streamed out, if 0, streamed out at a timer of 200
* ms
* @param detPos -1 for all detectors in list or specific detector position
* @returns receiver streaming frequency
*/
@ -1478,7 +1507,8 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK/FAIL
*/
int setCTBPatLoops(int level,int &start, int &stop, int &n, int detPos = -1);
int setCTBPatLoops(int level, int &start, int &stop, int &n,
int detPos = -1);
/**
* Sets the wait address in the CTB
@ -1501,8 +1531,9 @@ public:
/**
* Loads the detector setup from file
* @param fname file to read from
* @param level if 2 reads also reads trimbits, angular conversion coefficients etc.
* from files with default extensions as generated by dumpDetectorSetup
* @param level if 2 reads also reads trimbits, angular conversion
* coefficients etc. from files with default extensions as generated by
* dumpDetectorSetup
* @returns OK or FAIL
*/
int retrieveDetectorSetup(const std::string &fname, int level = 0);
@ -1510,8 +1541,8 @@ public:
/**
* Saves the detector setup to file
* @param fname file to write to
* @param level if 2 reads also trimbits, flat field, angular correction etc.
* and writes them to files with automatically added extension
* @param level if 2 reads also trimbits, flat field, angular correction
* etc. and writes them to files with automatically added extension
* @returns OK or FAIL
*/
int dumpDetectorSetup(const std::string &fname, int level = 0);
@ -1522,7 +1553,8 @@ public:
* gets detector status and progress index as arguments
* @param pArg argument
*/
void registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg);
void registerAcquisitionFinishedCallback(int (*func)(double, int, void *),
void *pArg);
/**
* register callback for accessing measurement final data
@ -1530,7 +1562,8 @@ public:
* gets detector status and progress index as arguments
* @param pArg argument
*/
void registerMeasurementFinishedCallback(int( *func)(int,int, void*), void *pArg);
void registerMeasurementFinishedCallback(int (*func)(int, int, void *),
void *pArg);
/**
* register callback for accessing detector progress
@ -1549,23 +1582,19 @@ public:
* s is for subframe number for eiger for 32 bit mode
* @param pArg argument
*/
void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg);
void registerDataCallback(int (*userCallback)(detectorData *, int, int,
void *),
void *pArg);
/**
* Performs a complete acquisition
* resets frames caught in receiver, starts receiver, starts detector,
* blocks till detector finished acquisition, stop receiver, increments file index,
* loops for measurements, calls required call backs.
* blocks till detector finished acquisition, stop receiver, increments file
* index, loops for measurements, calls required call backs.
* @returns OK or FAIL depending on if it already started
*/
int acquire();
/**
* Set/get if the data processing thread si enabled
* @param enable 0 no data processing thread, 1 separate thread, -1 get
*/
int setThreadedProcessing(int enable=-1);
/**
* Returns true if detector position is out of bounds
*/
@ -1575,11 +1604,12 @@ public:
* Combines data from all readouts and gives it to the gui
* or just gives progress of acquisition by polling receivers
*/
void* processData();
void processData();
private:
/**
* Initialize (open/create) shared memory for the sharedMultiDetector structure
* Initialize (open/create) shared memory for the sharedMultiDetector
* structure
* @param verify true to verify if shm size matches existing one
* @param update true to update last user pid, date etc
* @returns true if shared memory was created in this call, else false
@ -1618,7 +1648,8 @@ private:
/**
* add gap pixels to the image (only for Eiger in 4 bit mode)
* @param image pointer to image without gap pixels
* @param gpImage poiner to image with gap pixels, if NULL, allocated inside function
* @param gpImage poiner to image with gap pixels, if NULL, allocated inside
* function
* @returns number of data bytes of image with gap pixels
*/
int processImageWithGapPixels(char *image, char *&gpImage);
@ -1651,22 +1682,22 @@ private:
*/
void startProcessingThread();
/**
* Static function to call processing thread
*/
static void* startProcessData(void *n);
// /**
// * Static function to call processing thread
// */
// static void* startProcessData(void *n);
/**
* Check if processing thread is ready to join main thread
* @returns true if ready, else false
*/
int checkJoinThread();
bool getJoinThreadFlag() const;
/**
* Main thread sets if the processing thread should join it
* @param v true if it should join, else false
*/
void setJoinThread(int v);
void setJoinThreadFlag(bool value);
/**
* Listen to key event to stop acquiring
@ -1674,7 +1705,6 @@ private:
*/
int kbhit(void);
/** Multi detector Id */
int detId;
@ -1693,11 +1723,12 @@ private:
/** ZMQ Socket - Receiver to Client */
std::vector<std::unique_ptr<ZmqSocket>> zmqSocket;
/** semaphore to let postprocessing thread continue for next scan/measurement */
/** semaphore to let postprocessing thread continue for next
* scan/measurement */
sem_t sem_newRTAcquisition;
/** semaphore to let main thread know it got all the dummy packets (also from ext. process) */
/** semaphore to let main thread know it got all the dummy packets (also
* from ext. process) */
sem_t sem_endRTAcquisition;
/** Total number of frames/images for next acquisition */
@ -1707,19 +1738,20 @@ private:
int progressIndex;
/** mutex to synchronize main and data processing threads */
pthread_mutex_t mp;
mutable std::mutex mp;
/** mutex to synchronizedata processing and plotting threads */
pthread_mutex_t mg;
mutable std::mutex mg;
/** sets when the acquisition is finished */
int jointhread;
bool jointhread;
/** set when detector finishes acquiring */
int acquiringDone;
/** the data processing thread */
pthread_t dataProcessingThread;
// pthread_t dataProcessingThread;
std::thread dataProcessingThread;
/** gui data */
double *fdata;
@ -1738,14 +1770,6 @@ private:
int (*dataReady)(detectorData *, int, int, void *);
void *pCallbackArg;
};
#endif

View File

@ -400,7 +400,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
thisDetector->nTrimEn = 0;
for(int i = 0; i < MAX_TRIMEN; ++i)
thisDetector->trimEnergies[i] = 0;
thisDetector->threadedProcessing = 1;
// thisDetector->threadedProcessing = 1;
thisDetector->nROI = 0;
memset(thisDetector->roiLimits, 0, MAX_ROIS * sizeof(ROI));
thisDetector->roFlags = NORMAL_READOUT;

View File

@ -120,7 +120,7 @@ private:
/** threaded processing flag
* (i.e. if data are processed in a separate thread) */
int threadedProcessing;
// int threadedProcessing;
/** number of rois defined */
int nROI;

View File

@ -819,12 +819,12 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRateCorr;
++i;
/*! \page data
- <b>threaded [i]</b> Sets/gets the data processing threaded flag. 1 is threaded, 0 unthreaded.
*/
descrToFuncMap[i].m_pFuncName="threaded"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded;
++i;
// /*! \page data
// - <b>threaded [i]</b> Sets/gets the data processing threaded flag. 1 is threaded, 0 unthreaded.
// */
// descrToFuncMap[i].m_pFuncName="threaded"; //
// descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded;
// ++i;
/*! \page data
- <b>darkimage fn</b> Loads the dark image to the detector from file fn (pedestal image). Cannot get. For Gotthard only.
@ -2154,21 +2154,21 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action, int detPo
#ifdef VERBOSE
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
#endif
int b;
//int b;
if (action==PUT_ACTION) {
return string("cannot set");
} else if (action==HELP_ACTION) {
return helpData(HELP_ACTION);
} else {
b=myDet->setThreadedProcessing(-1);
myDet->setThreadedProcessing(0);
myDet->setOnline(ONLINE_FLAG, detPos);
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
myDet->readAll(detPos);
//processdata in receiver is useful only for gui purposes
if(myDet->setReceiverOnline(detPos)==OFFLINE_FLAG)
myDet->processData();
myDet->setThreadedProcessing(b);
// b=myDet->setThreadedProcessing(-1);
// myDet->setThreadedProcessing(0);
// myDet->setOnline(ONLINE_FLAG, detPos);
// myDet->setReceiverOnline(ONLINE_FLAG, detPos);
// myDet->readAll(detPos);
// //processdata in receiver is useful only for gui purposes
// if(myDet->setReceiverOnline(detPos)==OFFLINE_FLAG)
// myDet->processData();
// myDet->setThreadedProcessing(b);
return string("");
}
}
@ -2743,21 +2743,21 @@ string slsDetectorCommand::helpRateCorr(int action){
string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action, int detPos){
int ival;
char answer[1000];
// string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action, int detPos){
// int ival;
// char answer[1000];
if (action==HELP_ACTION)
return helpThreaded(action);
// if (action==HELP_ACTION)
// return helpThreaded(action);
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&ival))
myDet->setThreadedProcessing(ival);
}
sprintf(answer,"%d",myDet->setThreadedProcessing());
return string(answer);
// if (action==PUT_ACTION) {
// if (sscanf(args[1],"%d",&ival))
// myDet->setThreadedProcessing(ival);
// }
// sprintf(answer,"%d",myDet->setThreadedProcessing());
// return string(answer);
}
// }
string slsDetectorCommand::helpThreaded(int action){

View File

@ -113,7 +113,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
std::string cmdFileName(int narg, char *args[], int action, int detPos = -1);
std::string cmdFileIndex(int narg, char *args[], int action, int detPos = -1);
std::string cmdRateCorr(int narg, char *args[], int action, int detPos = -1);
std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1);
// std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1);
std::string cmdNetworkParameter(int narg, char *args[], int action, int detPos = -1);
std::string cmdPort(int narg, char *args[], int action, int detPos = -1);
std::string cmdLock(int narg, char *args[], int action, int detPos = -1);

View File

@ -42,7 +42,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* @param dataModifyReadycb pointer to data ready call back function with modified
* @param pDataReadycb pointer to arguments of data ready call back function. To write/stream a smaller size of processed data, change this value (only smaller value is allowed).
*/
DataProcessor(int ind, detectorType dtype, Fifo*& f, fileFormat* ftype,
DataProcessor(int ind, detectorType dtype, Fifo* f, fileFormat* ftype,
bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
uint32_t* freq, uint32_t* timer,
bool* fp, bool* act, bool* depaden, bool* sm,
@ -121,7 +121,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo*& f);
void SetFifo(Fifo* f);
/**
* Reset parameters for new acquisition (including all scans)

View File

@ -31,7 +31,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
* @param ajh additional json header
* @param sm pointer to silent mode
*/
DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector<ROI>* r,
DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector<ROI>* r,
uint64_t* fi, int* fd, char* ajh, bool* sm);
/**
@ -63,7 +63,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo*& f);
void SetFifo(Fifo* f);
/**
* Reset parameters for new acquisition (including all scans)

View File

@ -37,7 +37,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* @param depaden pointer to deactivated padding enable
* @param sm pointer to silent mode
*/
Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr,
uint32_t* us, uint32_t* as, uint32_t* fpf,
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm);
@ -96,7 +96,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo*& f);
void SetFifo(Fifo* f);
/**
* Reset parameters for new acquisition (including all scans)

View File

@ -9,7 +9,7 @@
#include "sls_detector_defs.h"
#include "receiver_defs.h"
#include "logger.h"
#include "container_utils.h"
class GeneralData;
class Listener;
class DataProcessor;
@ -18,6 +18,7 @@ class Fifo;
#include <exception>
#include <vector>
#include <memory>
class slsReceiverImplementation: private virtual slsDetectorDefs {
public:
@ -767,8 +768,6 @@ private:
//*** receiver parameters ***
/** Number of Threads */
int numThreads;
/** Number of Jobs */
int numberofJobs;
/** Number of channels in roi for jungfrauctb */
uint32_t nroichannels;
/** Maximum Number of Listening Threads/ UDP Ports */
@ -832,13 +831,13 @@ private:
/** General Data Properties */
GeneralData* generalData;
/** Listener Objects that listen to UDP and push into fifo */
std::vector <Listener*> listener;
std::vector<std::unique_ptr<Listener>> listener;
/** DataProcessor Objects that pull from fifo and process data */
std::vector <DataProcessor*> dataProcessor;
std::vector<std::unique_ptr<DataProcessor>> dataProcessor;
/** DataStreamer Objects that stream data via ZMQ */
std::vector <DataStreamer*> dataStreamer;
std::vector<std::unique_ptr<DataStreamer>> dataStreamer;
/** Fifo Structure to store addresses of memory writes */
std::vector <Fifo*> fifo;
std::vector<std::unique_ptr<Fifo>> fifo;
//***callback parameters***
/**

View File

@ -22,7 +22,7 @@
const std::string DataProcessor::TypeName = "DataProcessor";
DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo*& f,
DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
fileFormat* ftype, bool fwenable,
bool* dsEnable, bool* gpEnable, uint32_t* dr,
uint32_t* freq, uint32_t* timer,
@ -125,7 +125,7 @@ void DataProcessor::StopRunning() {
runningFlag = false;
}
void DataProcessor::SetFifo(Fifo*& f) {
void DataProcessor::SetFifo(Fifo* f) {
fifo = f;
}

View File

@ -15,7 +15,7 @@
const std::string DataStreamer::TypeName = "DataStreamer";
DataStreamer::DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector<ROI>* r,
DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector<ROI>* r,
uint64_t* fi, int* fd, char* ajh, bool* sm) :
ThreadObject(ind),
runningFlag(0),
@ -70,7 +70,7 @@ void DataStreamer::StopRunning() {
runningFlag = false;
}
void DataStreamer::SetFifo(Fifo*& f) {
void DataStreamer::SetFifo(Fifo* f) {
fifo = f;
}

View File

@ -18,7 +18,7 @@
const std::string Listener::TypeName = "Listener";
Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr,
uint32_t* us, uint32_t* as, uint32_t* fpf,
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) :
@ -108,7 +108,7 @@ void Listener::StopRunning() {
}
void Listener::SetFifo(Fifo*& f) {
void Listener::SetFifo(Fifo* f) {
fifo = f;
}

View File

@ -42,20 +42,9 @@ void slsReceiverImplementation::DeleteMembers() {
generalData=0;
}
for (auto* it : listener)
delete it;
listener.clear();
for (auto* it : dataProcessor)
delete it;
dataProcessor.clear();
for (auto* it : dataStreamer)
delete it;
dataStreamer.clear();
for (auto* it : fifo)
delete it;
fifo.clear();
}
@ -83,7 +72,6 @@ void slsReceiverImplementation::InitializeMembers() {
//*** receiver parameters ***
numThreads = 1;
numberofJobs = 1;
nroichannels = 0;
status = IDLE;
activated = true;
@ -217,14 +205,13 @@ uint64_t slsReceiverImplementation::getTotalFramesCaught() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
std::vector<DataProcessor*>::const_iterator it;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
flagsum += ((*it)->GetMeasurementStartedFlag() ? 1 : 0);
sum += (*it)->GetNumTotalFramesCaught();
for (const auto& it : dataProcessor){
flagsum += it->GetMeasurementStartedFlag();
sum += it->GetNumTotalFramesCaught();
}
//no data processed
if (flagsum != dataProcessor.size()) return 0;
if (flagsum != dataProcessor.size())
return 0;
return (sum/dataProcessor.size());
}
@ -233,13 +220,13 @@ uint64_t slsReceiverImplementation::getFramesCaught() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
flagsum += ((*it)->GetAcquisitionStartedFlag() ? 1 : 0);
sum += (*it)->GetNumFramesCaught();
for (const auto& it : dataProcessor){
flagsum += it->GetMeasurementStartedFlag();
sum += it->GetNumFramesCaught();
}
//no data processed
if (flagsum != dataProcessor.size()) return 0;
if (flagsum != dataProcessor.size())
return 0;
return (sum/dataProcessor.size());
}
@ -248,13 +235,13 @@ int64_t slsReceiverImplementation::getAcquisitionIndex() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it){
flagsum += ((*it)->GetAcquisitionStartedFlag() ? 1 : 0);
sum += (*it)->GetActualProcessedAcquisitionIndex();
for (const auto& it : dataProcessor){
flagsum += it->GetMeasurementStartedFlag();
sum += it->GetActualProcessedAcquisitionIndex();
}
//no data processed
if (flagsum != dataProcessor.size()) return -1;
if (flagsum != dataProcessor.size())
return -1;
return (sum/dataProcessor.size());
}
@ -409,25 +396,25 @@ void slsReceiverImplementation::setDetectorHostname(const char *c){
void slsReceiverImplementation::setMultiDetectorSize(const int* size) {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
char message[100];
strcpy(message, "Detector Size: (");
std::string log_message = "Detector Size: (";
for (int i = 0; i < MAX_DIMENSIONS; ++i) {
if (myDetectorType == EIGER && (!i))
numDet[i] = size[i]*2;
else
numDet[i] = size[i];
sprintf(message,"%s%d",message,numDet[i]);
log_message += std::to_string(numDet[i]);
if (i < MAX_DIMENSIONS-1 )
strcat(message,",");
log_message += ", ";
}
strcat(message,")");
FILE_LOG(logINFO) << message;
log_message += ")";
FILE_LOG(logINFO) << log_message;
}
void slsReceiverImplementation::setFlippedData(int axis, int enable){
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(axis<0 || axis>1) return;
if(axis<0 || axis>1)
return;
flippedData[axis] = enable==0?0:1;
FILE_LOG(logINFO) << "Flipped Data: " << flippedData[0] << " , " << flippedData[1];
}
@ -439,11 +426,8 @@ int slsReceiverImplementation::setGapPixelsEnable(const bool b) {
// side effects
generalData->SetGapPixelsEnable(b, dynamicRange);
// to update npixelsx, npixelsy in file writer
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetPixelDimension();
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
for (const auto& it : dataProcessor)
it->SetPixelDimension();
if (SetupFifoStructure() == FAIL)
return FAIL;
}
@ -463,9 +447,9 @@ void slsReceiverImplementation::setFileFormat(const fileFormat f){
fileFormatType = BINARY;
break;
}
//destroy file writer, set file format and create file writer
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetFileFormat(f);
for(const auto& it : dataProcessor)
it->SetFileFormat(f);
FILE_LOG(logINFO) << "File Format:" << getFileFormatType(fileFormatType);
}
@ -612,17 +596,15 @@ int slsReceiverImplementation::setROI(const std::vector<slsDetectorDefs::ROI> i)
generalData->SetROI(i);
framesPerFile = generalData->maxFramesPerFile;
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->SetGeneralData(generalData);
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetGeneralData(generalData);
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
(*it)->SetGeneralData(generalData);
for (const auto& it : listener)
it->SetGeneralData(generalData);
for (const auto& it : dataProcessor)
it->SetGeneralData(generalData);
for (const auto& it : dataStreamer)
it->SetGeneralData(generalData);
}
@ -667,22 +649,17 @@ int slsReceiverImplementation::setDataStreamEnable(const bool enable) {
dataStreamEnable = enable;
//data sockets have to be created again as the client ones are
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
delete(*it);
dataStreamer.clear();
if (enable) {
for ( int i = 0; i < numThreads; ++i ) {
try {
DataStreamer* s = new DataStreamer(i, fifo[i], &dynamicRange,
&roi, &fileIndex, flippedData, additionalJsonHeader, &silentMode);
dataStreamer.push_back(s);
dataStreamer.push_back(sls::make_unique<DataStreamer>(i, fifo[i].get(), &dynamicRange,
&roi, &fileIndex, flippedData, additionalJsonHeader, &silentMode));
dataStreamer[i]->SetGeneralData(generalData);
dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP);
}
catch(...) {
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
delete(*it);
dataStreamer.clear();
dataStreamEnable = false;
return FAIL;
@ -767,7 +744,6 @@ int slsReceiverImplementation::setNumberofSamples(const uint64_t i) {
numberOfSamples = i;
generalData->setNumberofSamples(i, nroichannels);
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
@ -780,15 +756,11 @@ int slsReceiverImplementation::setNumberofSamples(const uint64_t i) {
int slsReceiverImplementation::setDynamicRange(const uint32_t i) {
if (dynamicRange != i) {
dynamicRange = i;
//side effects
generalData->SetDynamicRange(i,tengigaEnable);
generalData->SetGapPixelsEnable(gapPixelsEnable, dynamicRange);
// to update npixelsx, npixelsy in file writer
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetPixelDimension();
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
for (const auto& it : dataProcessor)
it->SetPixelDimension();
if (SetupFifoStructure() == FAIL)
return FAIL;
}
@ -802,8 +774,6 @@ int slsReceiverImplementation::setTenGigaEnable(const bool b) {
tengigaEnable = b;
//side effects
generalData->SetTenGigaEnable(b,dynamicRange);
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
@ -815,8 +785,6 @@ int slsReceiverImplementation::setTenGigaEnable(const bool b) {
int slsReceiverImplementation::setFifoDepth(const uint32_t i) {
if (fifoDepth != i) {
fifoDepth = i;
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
@ -887,11 +855,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
udpSocketBufferSize = generalData->defaultUdpSocketBufferSize;
framesPerFile = generalData->maxFramesPerFile;
//local network parameters
SetLocalNetworkParameters();
//create fifo structure
numberofJobs = -1;
if (SetupFifoStructure() == FAIL) {
FILE_LOG(logERROR) << "Could not allocate memory for fifo structure";
return FAIL;
@ -901,37 +865,31 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
for ( int i = 0; i < numThreads; ++i ) {
try {
Listener* l = new Listener(i, myDetectorType, fifo[i], &status,
auto fifo_ptr = fifo[i].get();
listener.push_back(sls::make_unique<Listener>(i, myDetectorType, fifo_ptr, &status,
&udpPortNum[i], eth, &numberOfFrames, &dynamicRange,
&udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile,
&frameDiscardMode, &activated, &deactivatedPaddingEnable, &silentMode);
listener.push_back(l);
DataProcessor* p = new DataProcessor(i, myDetectorType, fifo[i], &fileFormatType,
&frameDiscardMode, &activated, &deactivatedPaddingEnable, &silentMode));
dataProcessor.push_back(sls::make_unique<DataProcessor>(i, myDetectorType, fifo_ptr, &fileFormatType,
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable,
&dynamicRange, &streamingFrequency, &streamingTimerInMs,
&framePadding, &activated, &deactivatedPaddingEnable, &silentMode,
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady);
dataProcessor.push_back(p);
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady));
}
catch (...) {
FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")";
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
delete(*it);
listener.clear();
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
delete(*it);
dataProcessor.clear();
return FAIL;
}
}
//set up writer and callbacks
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->SetGeneralData(generalData);
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetGeneralData(generalData);
for (const auto& it : listener)
it->SetGeneralData(generalData);
for (const auto& it : dataProcessor)
it->SetGeneralData(generalData);
SetThreadPriorities();
// check udp socket buffer size
@ -967,14 +925,12 @@ void slsReceiverImplementation::setDetectorPositionId(const int i){
/***acquisition functions***/
void slsReceiverImplementation::resetAcquisitionCount() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
for (const auto& it : listener)
it->ResetParametersforNewAcquisition();
for (const auto& it : dataProcessor)
it->ResetParametersforNewAcquisition();
for (const auto& it: dataStreamer)
it->ResetParametersforNewAcquisition();
FILE_LOG(logINFO) << "Acquisition Count has been reset";
}
@ -996,7 +952,7 @@ int slsReceiverImplementation::startReceiver(char *c) {
//callbacks
if (startAcquisitionCallBack) {
startAcquisitionCallBack(filePath, fileName, fileIndex,
(generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize), pStartAcquisition);
(generalData->imageSize) + (generalData->fifoBufferHeaderSize), pStartAcquisition);
if (rawDataReadyCallBack != NULL) {
FILE_LOG(logINFO) << "Data Write has been defined externally";
}
@ -1038,11 +994,12 @@ void slsReceiverImplementation::stopReceiver(){
bool running = true;
while(running) {
running = false;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
if ((*it)->IsRunning())
for (const auto& it : listener)
if (it->IsRunning())
running = true;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
if ((*it)->IsRunning())
for (const auto& it : dataProcessor)
if (it->IsRunning())
running = true;
usleep(5000);
}
@ -1052,9 +1009,9 @@ void slsReceiverImplementation::stopReceiver(){
if (fileWriteEnable && fileFormatType == HDF5) {
uint64_t maxIndexCaught = 0;
bool anycaught = false;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
maxIndexCaught = std::max(maxIndexCaught, (*it)->GetProcessedMeasurementIndex());
if((*it)->GetMeasurementStartedFlag())
for (const auto& it : dataProcessor) {
maxIndexCaught = std::max(maxIndexCaught, it->GetProcessedMeasurementIndex());
if(it->GetMeasurementStartedFlag())
anycaught = true;
}
//to create virtual file & set files/acquisition to 0 (only hdf5 at the moment)
@ -1065,8 +1022,8 @@ void slsReceiverImplementation::stopReceiver(){
running = true;
while(running) {
running = false;
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
if ((*it)->IsRunning())
for (const auto& it : dataStreamer)
if (it->IsRunning())
running = true;
usleep(5000);
}
@ -1107,46 +1064,39 @@ void slsReceiverImplementation::stopReceiver(){
void slsReceiverImplementation::startReadout(){
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(status == RUNNING){
// wait for incoming delayed packets
//current packets caught
volatile int totalP = 0,prev=-1;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetPacketsCaught();
int totalPacketsReceived = 0;
int previousValue=-1;
for(const auto& it : listener)
totalPacketsReceived += it->GetPacketsCaught();
//wait for all packets
if((unsigned long long int)totalP!=numberOfFrames*generalData->packetsPerFrame*listener.size()){
const auto numPacketsToReceive = numberOfFrames * generalData->packetsPerFrame * listener.size();
if(totalPacketsReceived != numPacketsToReceive){
while(totalPacketsReceived != previousValue){
FILE_LOG(logDEBUG3) << "waiting for all packets, previousValue:" << previousValue <<
" totalPacketsReceived: " << totalPacketsReceived;
usleep(5*1000);/* TODO! Need to find optimal time **/
previousValue = totalPacketsReceived;
totalPacketsReceived = 0;
for(const auto& it : listener)
totalPacketsReceived += it->GetPacketsCaught();
//wait as long as there is change from prev totalP,
while(prev != totalP){
FILE_LOG(logDEBUG3) << "waiting for all packets prevP:" << prev <<
" totalP: " << totalP;
//usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);
usleep(5*1000);/* Need to find optimal time **/
prev = totalP;
totalP = 0;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetPacketsCaught();
FILE_LOG(logDEBUG3) << "\tupdated: totalP:" << totalP;
FILE_LOG(logDEBUG3) << "\tupdated: totalPacketsReceived:" << totalPacketsReceived;
}
}
//set status
status = TRANSMITTING;
FILE_LOG(logINFO) << "Status: Transmitting";
}
//shut down udp sockets so as to make listeners push dummy (end) packets for processors
//shut down udp sockets to make listeners push dummy (end) packets for processors
shutDownUDPSockets();
}
void slsReceiverImplementation::shutDownUDPSockets() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ShutDownUDPSocket();
for (const auto& it : listener)
it->ShutDownUDPSocket();
}
@ -1155,10 +1105,10 @@ void slsReceiverImplementation::closeFiles() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
uint64_t maxIndexCaught = 0;
bool anycaught = false;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
(*it)->CloseFiles();
maxIndexCaught = std::max(maxIndexCaught, (*it)->GetProcessedMeasurementIndex());
if((*it)->GetMeasurementStartedFlag())
for (const auto& it : dataProcessor) {
it->CloseFiles();
maxIndexCaught = std::max(maxIndexCaught, it->GetProcessedMeasurementIndex());
if(it->GetMeasurementStartedFlag())
anycaught = true;
}
//to create virtual file & set files/acquisition to 0 (only hdf5 at the moment)
@ -1169,11 +1119,10 @@ void slsReceiverImplementation::closeFiles() {
int slsReceiverImplementation::restreamStop() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
bool ret = OK;
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it) {
if ((*it)->RestreamStop() == FAIL)
for (const auto& it : dataStreamer){
if (it->RestreamStop() == FAIL)
ret = FAIL;
}
// if fail, prints in datastreamer
if (ret == OK) {
FILE_LOG(logINFO) << "Restreaming Dummy Header via ZMQ successful";
@ -1238,8 +1187,8 @@ void slsReceiverImplementation::SetLocalNetworkParameters() {
void slsReceiverImplementation::SetThreadPriorities() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it){
if ((*it)->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
for (const auto& it : listener){
if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
FILE_LOG(logWARNING) << "Could not prioritize listener threads. (No Root Privileges?)";
return;
}
@ -1254,34 +1203,27 @@ void slsReceiverImplementation::SetThreadPriorities() {
int slsReceiverImplementation::SetupFifoStructure() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
numberofJobs = 1;
for (std::vector<Fifo*>::const_iterator it = fifo.begin(); it != fifo.end(); ++it)
delete(*it);
fifo.clear();
for ( int i = 0; i < numThreads; ++i ) {
//create fifo structure
try {
Fifo* f = new Fifo (i,
(generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize),
fifoDepth);
fifo.push_back(f);
fifo.push_back(sls::make_unique<Fifo>(i,
(generalData->imageSize) + (generalData->fifoBufferHeaderSize),
fifoDepth));
} catch (...) {
FILE_LOG(logERROR) << "Could not allocate memory for fifo structure of index " << i;
for (std::vector<Fifo*>::const_iterator it = fifo.begin(); it != fifo.end(); ++it)
delete(*it);
fifo.clear();
return FAIL;
}
//set the listener & dataprocessor threads to point to the right fifo
if(listener.size())listener[i]->SetFifo(fifo[i]);
if(dataProcessor.size())dataProcessor[i]->SetFifo(fifo[i]);
if(dataStreamer.size())dataStreamer[i]->SetFifo(fifo[i]);
if(listener.size())listener[i]->SetFifo(fifo[i].get());
if(dataProcessor.size())dataProcessor[i]->SetFifo(fifo[i].get());
if(dataStreamer.size())dataStreamer[i]->SetFifo(fifo[i].get());
}
FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " << ( ((generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize)) * fifoDepth) << " bytes" ;
FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " << ( ((generalData->imageSize) + (generalData->fifoBufferHeaderSize)) * fifoDepth) << " bytes" ;
FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed";
return OK;
}
@ -1290,16 +1232,17 @@ int slsReceiverImplementation::SetupFifoStructure() {
void slsReceiverImplementation::ResetParametersforNewMeasurement() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewMeasurement();
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->ResetParametersforNewMeasurement();
for (const auto& it : listener)
it->ResetParametersforNewMeasurement();
for (const auto& it : dataProcessor)
it->ResetParametersforNewMeasurement();
if (dataStreamEnable) {
char fnametostream[MAX_STR_LENGTH];
snprintf(fnametostream, MAX_STR_LENGTH, "%s/%s", filePath, fileName);
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
(*it)->ResetParametersforNewMeasurement(fnametostream);
for (const auto& it : dataStreamer)
it->ResetParametersforNewMeasurement(fnametostream);
}
}
@ -1345,16 +1288,16 @@ int slsReceiverImplementation::SetupWriter() {
void slsReceiverImplementation::StartRunning() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
//set running mask and post semaphore to start the inner loop in execution thread
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) {
(*it)->StartRunning();
(*it)->Continue();
for (const auto& it : listener){
it->StartRunning();
it->Continue();
}
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it){
(*it)->StartRunning();
(*it)->Continue();
for (const auto& it : dataProcessor){
it->StartRunning();
it->Continue();
}
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it){
(*it)->StartRunning();
(*it)->Continue();
for (const auto& it : dataStreamer){
it->StartRunning();
it->Continue();
}
}

View File

@ -99,6 +99,7 @@ T minusOneIfDifferent(const std::vector<T>& container)
}
//TODO!(Erik)Should try to move away from using this in the slsDetectorPackage
inline
std::string concatenateIfDifferent(std::vector<std::string> container)
{
if (allEqual(container)) {
@ -110,7 +111,7 @@ std::string concatenateIfDifferent(std::vector<std::string> container)
return result;
}
}
inline
std::vector<std::string> split(const std::string& strToSplit, char delimeter)
{
std::stringstream ss(strToSplit);
@ -122,6 +123,7 @@ std::vector<std::string> split(const std::string& strToSplit, char delimeter)
return splittedStrings;
}
inline
std::string concatenateNonEmptyStrings(const std::vector<std::string>& vec){
std::string ret;
for (const auto& s : vec)