Commandline (#66)

* WIP

* WIP

* removed status to string from defs

* WIP

* WIP

* WIP removed unused functions in multi

* WIP

* print hex in a terrible way

* WIP, loadconfig error

* WIP, type to string

* WIP

* fix to conversion

* WIP, hostname doesnt work

* WIP

* WIP

* WIP

* WIP, threshold

* WIP, threshold

* WIP

* WIP, triggers

* WIP, cycles to triggers

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* rx_udsocksize fx, WIP

* WIP

* WIP

* WIP

* file index (64 bit), WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* merge

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* New python mod
This commit is contained in:
Dhanya Thattil
2019-10-21 10:29:06 +02:00
committed by GitHub
parent eebc1109b0
commit 995f0924e5
95 changed files with 5320 additions and 8114 deletions

View File

@ -1,7 +1,7 @@
set(SOURCES
src/multiSlsDetector.cpp
src/multiSlsDetectorClient.cpp
src/slsDetectorUsers.cpp
# src/slsDetectorUsers.cpp
src/slsDetectorCommand.cpp
src/slsDetector.cpp
src/Detector.cpp
@ -39,7 +39,7 @@ target_link_libraries(slsDetectorShared PUBLIC
set(PUBLICHEADERS
include/SharedMemory.h
include/slsDetector.h
include/slsDetectorUsers.h
# include/slsDetectorUsers.h
include/detectorData.h
include/multiSlsDetector.h
include/Detector.h

File diff suppressed because it is too large Load Diff

View File

@ -52,14 +52,17 @@ class Detector {
/** Gets shared memory ID */
int getShmId() const;
/** package git branch */
std::string getPackageVersion() const;
int64_t getClientVersion() const;
Result<int64_t> getFirmwareVersion(Positions pos = {}) const;
Result<int64_t> getDetectorServerVersion(Positions pos = {}) const;
Result<int64_t> getSerialNumber(Positions pos = {}) const;
int64_t getClientVersion() const;
Result<int64_t> getReceiverVersion(Positions pos = {}) const;
Result<defs::detectorType> getDetectorType(Positions pos = {}) const;
@ -197,7 +200,7 @@ class Detector {
Result<int> getDAC(defs::dacIndex index, bool mV, Positions pos = {}) const;
void setDAC(int value, defs::dacIndex index, bool mV, Positions pos = {});
void setDAC(defs::dacIndex index, int value, bool mV, Positions pos = {});
Result<defs::timingMode> getTimingMode(Positions pos = {}) const;
@ -213,33 +216,33 @@ class Detector {
* *
* ************************************************/
/**
* Blocking call, starts the receiver and detector.
* Increments file index if file write enabled.
* Acquired the number of frames set.
* Blocking call: Acquire the number of frames set
* - sets acquiring flag
* - starts the receiver listener
* - starts detector acquisition for number of frames set
* - monitors detector status from running to idle
* - stops the receiver listener
* - increments file index if file write enabled
* - resets acquiring flag
*/
void acquire();
/** Non blocking
* Starts the reciever (if enabled) and then the detector
* You have to check detector status until it is idle before you call
* stopACquisition
*
*/
void startAcquisition();
/**
* Stops detector acquisition and then receiver (if enabled)
* If no receiver enabled, you can skip this for normal acquisition (no
* abort)
*/
void stopAcquisition();
/** TODO: initially was getting acq flag, if set, check if detctor idle, then set, else exception & abort
* Clears the acquiring flag. This has to be done manually
* after an acquisition was aborted.
*/
/** If acquisition aborted, use this to clear before starting next acquisition */
void clearAcquiringFlag();
/** Non Blocking: Start receiver listener*/
void startReceiver();
/** Non Blocking: Stop receiver listener */
void stopReceiver();
/** Non blocking: start detector acquisition
* detector status changes from RUNNING to IDLE when finished */
void startDetector();
/** Non blocking: abort detector acquisition */
void stopDetector();
Result<defs::runStatus> getDetectorStatus(Positions pos = {}) const;
Result<defs::runStatus> getReceiverStatus(Positions pos = {}) const;
@ -337,8 +340,6 @@ class Detector {
/** module_id is -1 for all detectors, ports for each module is calculated
* (increments) */
// TODO if Parallel takes a vector, can send multiple vaues to set in
// slsdetector.cp
void setDestinationUDPPort(int port, int module_id = -1);
/** [Eiger right port][Jungfrau bottom half] */
@ -397,7 +398,7 @@ class Detector {
/**************************************************
* *
* RECEIVER CONFIG *
* Receiver Config *
* *
* ************************************************/
@ -416,8 +417,10 @@ class Detector {
Result<int> getRxPort(Positions pos = {}) const;
/** Receiver TCP port (for client communication with Receiver) */
void setRxPort(int value, Positions pos = {});
/** Receiver TCP port (for client communication with Receiver)
* module_id is -1 for all detectors, ports for each module is calculated
* (increments) */
void setRxPort(int port, int module_id = -1);
Result<int> getRxFifoDepth(Positions pos = {}) const;
@ -458,11 +461,11 @@ class Detector {
/** locks receiver server to client IP */
void setRxLock(bool value, Positions pos = {});
Result<std::string> getRxLastClientIP(Positions pos = {}) const;
Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const;
/**************************************************
* *
* FILE *
* File *
* *
* ************************************************/
Result<defs::fileFormat> getFileFormat(Positions pos = {}) const;
@ -483,9 +486,9 @@ class Detector {
*/
void setFileNamePrefix(const std::string &fname, Positions pos = {});
Result<int> getAcquisitionIndex(Positions pos = {}) const;
Result<int64_t> getAcquisitionIndex(Positions pos = {}) const;
void setAcquisitionIndex(int i, Positions pos = {});
void setAcquisitionIndex(int64_t i, Positions pos = {});
Result<bool> getFileWrite(Positions pos = {}) const;
@ -545,23 +548,23 @@ class Detector {
*/
void setRxZmqPort(int port, int module_id = -1);
Result<std::string> getRxZmqIP(Positions pos = {}) const;
Result<IpAddr> getRxZmqIP(Positions pos = {}) const;
void setRxZmqIP(const std::string &ip, Positions pos = {});
void setRxZmqIP(const IpAddr ip, Positions pos = {});
Result<int> getClientZmqPort(Positions pos = {}) const;
/**
* Needed only when using the client call back to get reconstructed data
* from multi modules module_id is -1 for all detectors, ports for each
* module is calculated (increments) Restarts client zmq sockets oonly if it
* Modified only when using an intermediate process between receiver and gui/client.
* Module_id is -1 for all detectors, ports for each
* module is calculated (increments) Restarts client zmq sockets only if it
* was already enabled
*/
void setClientZmqPort(int port, int module_id = -1);
Result<std::string> getClientZmqIp(Positions pos = {}) const;
Result<IpAddr> getClientZmqIp(Positions pos = {}) const;
void setClientZmqIp(const std::string &ip, Positions pos = {});
void setClientZmqIp(const IpAddr ip, Positions pos = {});
/**************************************************
* *
@ -599,10 +602,10 @@ class Detector {
bool trimbits = true, Positions pos = {});
/** [Eiger] */
Result<std::string> getSettingsDir(Positions pos = {}) const;
Result<std::string> getSettingsPath(Positions pos = {}) const;
/** [Eiger] */
void setSettingsDir(const std::string &value, Positions pos = {});
void setSettingsPath(const std::string &value, Positions pos = {});
/** [Eiger] */
void loadTrimbits(const std::string &fname, Positions pos = {});
@ -808,13 +811,15 @@ class Detector {
* Can set only a single ROI at a time
* @param module position index
*/
void setROI(defs::ROI value, int moduleId);
void setROI(defs::ROI value, int module_id);
/** [Gotthard] TODO: check with jiaguo if he needs any of these functions //
* TODO remove */
/** [Gotthard] Clear ROI */
void clearROI(Positions pos = {});
/** [Gotthard] */
Result<ns> getExptimeLeft(Positions pos = {}) const;
/** [Gotthard] TODO remove */
/** [Gotthard] */
Result<ns> getPeriodLeft(Positions pos = {}) const;
/** [Gotthard] */
@ -904,12 +909,6 @@ class Detector {
/** [CTB] */
void setDBITPipeline(int value, Positions pos = {});
/** [CTB] */
Result<int> getVrefVoltage(bool mV, Positions pos = {}) const;
/** [CTB] */
void setVrefVoltage(int value, bool mV, Positions pos = {});
/** [CTB] */
Result<int> getVoltage(defs::dacIndex index, Positions pos = {}) const;
@ -918,20 +917,17 @@ class Detector {
* Options: V_LIMIT, V_POWER_A, V_POWER_B, V_POWER_C,
* V_POWER_D, V_POWER_IO, V_POWER_CHIP
*/
void setVoltage(int value, defs::dacIndex index, Positions pos = {});
void setVoltage(defs::dacIndex index, int value, Positions pos = {});
/**
* [CTB] mV
* Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO,
* V_POWER_CHIP
*/
* Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO */
Result<int> getMeasuredVoltage(defs::dacIndex index,
Positions pos = {}) const;
/**
* [CTB] mA
* Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO
*/
* Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO */
Result<int> getMeasuredCurrent(defs::dacIndex index,
Positions pos = {}) const;
@ -990,7 +986,7 @@ class Detector {
/**************************************************
* *
* PATTERN *
* Pattern *
* *
* ************************************************/
@ -1012,6 +1008,9 @@ class Detector {
/** [CTB] */
void setPatternClockControl(uint64_t word, Positions pos = {});
/** [CTB] same as executing */
Result<uint64_t> getPatternWord(int addr, Positions pos = {});
/** [CTB] Caution: If word is -1 reads the addr (same as
* executing the pattern) */
void setPatternWord(int addr, uint64_t word, Positions pos = {});
@ -1178,7 +1177,7 @@ class Detector {
void setDetectorLock(bool lock, Positions pos = {});
/** Get last client IP saved on detector server */
Result<std::string> getLastClientIP(Positions pos = {}) const;
Result<sls::IpAddr> getLastClientIP(Positions pos = {}) const;
/** Execute a command on the detector server console */
void executeCommand(const std::string &value, Positions pos = {});

View File

@ -261,6 +261,12 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int getMultiId() const { return multiId; } // part of multi also
/**
* Get package version (git branch)
* @returns package version
*/
std::string getPackageVersion() const;
/**
* Get Client Software version
* @returns client software version
@ -453,13 +459,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
int lockServer(int p = -1, int detPos = -1); //
/**
* Get last client IP saved on detector server
* @param detPos -1 for all detectors in list or specific detector position
* @returns last client IP saved on detector server
*/
std::string getLastClientIP(int detPos = -1); //
/**
* Exit detector server
* @param detPos -1 for all detectors in list or specific detector position
@ -553,31 +552,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
void saveSettingsFile(const std::string &fname, int detPos = -1); //
/**
* Get Detector run status
* @param detPos -1 for all detectors in list or specific detector position
* @returns status
*/
runStatus getRunStatus(int detPos = -1); //
/**
* Start detector acquisition (Non blocking)
* @param detPos -1 for all detectors in list or specific detector position
*/
void startAcquisition(int detPos = -1); //
/**
* Stop detector acquisition
* @param detPos -1 for all detectors in list or specific detector position
*/
void stopAcquisition(int detPos = -1); //
/**
* Give an internal software trigger to the detector (Eiger only)
* @param detPos -1 for all detectors in list or specific detector position
*/
void sendSoftwareTrigger(int detPos = -1); //
/**
* Configures in detector the destination for UDP packets
* @param detPos -1 for all detectors in list or specific detector position
@ -669,12 +643,12 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int64_t setNumberOfFrames(int64_t t = -1, int detPos = -1); //
/**
* Set/get number of cycles
* @param t number of cycles (-1 gets)
* Set/get number of triggers
* @param t number of triggers (-1 gets)
* @param detPos -1 for all detectors in list or specific detector position
* @returns number of cycles
* @returns number of triggers
*/
int64_t setNumberOfCycles(int64_t t = -1, int detPos = -1); //
int64_t setNumberOfTriggers(int64_t t = -1, int detPos = -1); //
/**
* Set/get number of additional storage cells (Jungfrau)
@ -929,45 +903,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
int getReceiverStreamingPort(int detPos = -1); //
/**
* (advanced users)
* Set/Get client streaming in ZMQ IP and restarts client sockets
* @param i sets, empty string gets
* By default, it is the IP of receiver hostname
* @param detPos -1 for all detectors in list or specific detector position
*/
void setClientDataStreamingInIP(const std::string &ip = "",
int detPos = -1); //
/**
* Returns the client zmq ip
* If detPos is -1(multi module), ip returns concatenation of all client
* streaming ip
* @param detPos -1 for all detectors in list or specific detector position
* @returns the client zmq ip
*/
std::string getClientStreamingIP(int detPos = -1); //
/**
* (advanced users)
* Set/Get receiver streaming out ZMQ IP and restarts receiver sockets
* @param i sets, empty string gets
* By default, it is the IP of receiver hostname
* @param detPos -1 for all detectors in list or specific detector position
*/
void setReceiverDataStreamingOutIP(const std::string &ip = "",
int detPos = -1); //
/**
* Returns the receiver zmq ip
* If detPos is -1(multi module), ip returns concatenation of all receiver
* streaming ip
* @param detPos -1 for all detectors in list or specific detector position
* @returns the receiver zmq ip
*/
std::string getReceiverStreamingIP(int detPos = -1); //
/**
/**
* Sets the transmission delay for left, right or entire frame
* (Eiger, Jungfrau(only entire frame))
* @param index type of delay
@ -1435,13 +1371,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
int lockReceiver(int lock = -1, int detPos = -1); //
/**
* Returns the IP of the last client connecting to the receiver
* @param detPos -1 for all detectors in list or specific detector position
* @returns IP of last client connecting to receiver
*/
std::string getReceiverLastClientIP(int detPos = -1); //
/**
* Turns off the receiver server!
* @param detPos -1 for all detectors in list or specific detector position
@ -1541,7 +1470,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param detPos -1 for all detectors in list or specific detector position
* @returns file index
*/
int setFileIndex(int i, int detPos = -1); //
int64_t setFileIndex(int64_t i, int detPos = -1); //
/**
* Get File index
@ -1549,26 +1478,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* position
* @returns file index
*/
int getFileIndex(int detPos = -1) const; //
/**
* Receiver starts listening to packets
* @param detPos -1 for all detectors in list or specific detector position
*/
void startReceiver(int detPos = -1); //
/**
* Stops the listening mode of receiver
* @param detPos -1 for all detectors in list or specific detector position
*/
void stopReceiver(int detPos = -1); //
/**
* Gets the status of the listening mode of receiver
* @param detPos -1 for all detectors in list or specific detector position
* @returns status
*/
runStatus getReceiverStatus(int detPos = -1); //
int64_t getFileIndex(int detPos = -1) const; //
/**
* Gets the number of frames caught by receiver
@ -1820,21 +1730,8 @@ class multiSlsDetector : public virtual slsDetectorDefs {
/**
* 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
* @returns OK or FAIL
*/
int retrieveDetectorSetup(const std::string &fname, int level = 0);
/**
* 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
* @returns OK or FAIL
*/
int dumpDetectorSetup(const std::string &fname, int level = 0);
void loadParameters(const std::string &fname);
/**
* register callback for accessing acquisition final data
@ -1916,12 +1813,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
void updateUserdetails();
/**
* Prepares detector for acquisition (Eiger)
* @param detPos -1 for all detectors in list or specific detector position
*/
void prepareAcquisition(int detPos = -1); //
/**
* Check if acquiring flag is set, set error if set
* @returns FAIL if not ready, OK if ready
@ -1935,14 +1826,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
std::string exec(const char *cmd);
/**
* Appends detectors to the end of the list in shared memory
* Connects to them
* @param name concatenated hostname of the sls detectors to be appended to
* the list
*/
void addMultipleDetectors(const char *name); //
/**
* Add sls detector
* @param s hostname of the single detector
@ -1960,7 +1843,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param detPos -1 for all detectors in list or specific detector position
* @returns the file index
*/
int incrementFileIndex(int detPos = -1);
int64_t incrementFileIndex(int detPos = -1);
/**
* add gap pixels to the image (only for Eiger in 4 bit mode)
@ -2013,26 +1896,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
void startProcessingThread();
/**
* Start detector acquisition and read all data (Blocking until end of
* acquisition)
* @param detPos -1 for all detectors in list or specific detector position
*/
void startAndReadAll(int detPos = -1); //
/**
* Start readout (without exposure or interrupting exposure) (Eiger store in
* ram)
* @param detPos -1 for all detectors in list or specific detector position
*/
void startReadOut(int detPos = -1); //
/**
* Requests and receives all data from the detector (Eiger store in ram)
* @param detPos -1 for all detectors in list or specific detector position
*/
void readAll(int detPos = -1); //
/**
* Check if processing thread is ready to join main thread
* @returns true if ready, else false

View File

@ -148,7 +148,7 @@ struct sharedSlsDetector {
char rxFileName[MAX_STR_LENGTH];
/** file index */
int rxFileIndex;
int64_t rxFileIndex;
/** file format */
slsDetectorDefs::fileFormat rxFileFormat;
@ -350,7 +350,7 @@ class slsDetector : public virtual slsDetectorDefs {
* Get last client IP saved on detector server
* @returns last client IP saved on detector server
*/
std::string getLastClientIP();
sls::IpAddr getLastClientIP();
/**
* Exit detector server
@ -896,29 +896,32 @@ class slsDetector : public virtual slsDetectorDefs {
/**
* Sets the client zmq ip\sa sharedSlsDetector
* @param sourceIP client zmq ip
* @param ip client zmq ip
*/
void setClientStreamingIP(const std::string &sourceIP);
void setClientStreamingIP(const sls::IpAddr ip);
/**
* Returns the client zmq ip \sa sharedSlsDetector
* @returns the client zmq ip, returns "none" if default setting and no
* custom ip set
* @returns the client zmq ip
*/
std::string getClientStreamingIP();
sls::IpAddr getClientStreamingIP();
/**
* Sets the receiver zmq ip\sa sharedSlsDetector
* @param sourceIP receiver zmq ip. If empty, uses rx_hostname
* @param ip receiver zmq ip
*/
void setReceiverStreamingIP(std::string sourceIP);
void setReceiverStreamingIP(const sls::IpAddr ip);
/**
* Returns the receiver zmq ip \sa sharedSlsDetector
* @returns the receiver zmq ip, returns "none" if default setting and no
* custom ip set
* @returns the receiver zmq ip
*/
std::string getReceiverStreamingIP();
sls::IpAddr getReceiverStreamingIP();
/** update receiver stremaing ip from shm to receiver
* if empty, use rx_hostname ip
*/
void updateReceiverStreamingIP();
/**
* Sets the transmission delay for left, right or entire frame
@ -1333,7 +1336,7 @@ class slsDetector : public virtual slsDetectorDefs {
* Returns the IP of the last client connecting to the receiver
* @returns the IP of the last client connecting to the receiver
*/
std::string getReceiverLastClientIP() const;
sls::IpAddr getReceiverLastClientIP() const;
/**
* Exits the receiver TCP server
@ -1440,19 +1443,19 @@ class slsDetector : public virtual slsDetectorDefs {
* @param i file index
* @returns file index
*/
int setFileIndex(int file_index);
int64_t setFileIndex(int64_t file_index);
/**
* Gets the file index
* @returns file index
*/
int getFileIndex() const;
int64_t getFileIndex() const;
/**
* increments file index
* @returns the file index
*/
int incrementFileIndex();
int64_t incrementFileIndex();
/**
* Receiver starts listening to packets

View File

@ -42,40 +42,22 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
std::string helpLine(int narg, const char * const args[], int action=HELP_ACTION, int detPos = -1);
static std::string helpAcquire(int action);
static std::string helpData(int action);
static std::string helpStatus(int action);
static std::string helpDataStream(int action);
static std::string helpFree(int action);
static std::string helpHostname(int action);
static std::string helpUser(int action);
static std::string helpExitServer(int action);
static std::string helpSettingsDir(int action);
static std::string helpTrimEn(int action);
static std::string helpOutDir(int action);
static std::string helpFileName(int action);
static std::string helpRateCorr(int action);
static std::string helpThreaded(int action);
static std::string helpNetworkParameter(int action);
static std::string helpPort(int action);
static std::string helpLastClient(int action);
static std::string helpOnline(int action);
static std::string helpDetectorSize(int action);
static std::string helpSettings(int action);
static std::string helpSN(int action);
static std::string helpDigiTest(int action);
static std::string helpRegister(int action);
static std::string helpDAC(int action);
static std::string helpTimer(int action);
static std::string helpTiming(int action);
static std::string helpTimeLeft(int action);
static std::string helpSpeed(int action);
static std::string helpAdvanced(int action);
static std::string helpConfiguration(int action);
static std::string helpCounter(int action);
static std::string helpADC(int action);
static std::string helpTempControl(int action);
static std::string helpReceiver(int action);
static std::string helpPattern(int action);
static std::string helpPulse(int action);
static std::string helpProcessor(int action);
private:
@ -85,40 +67,22 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
std::string cmdUnknown(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdAcquire(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdData(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdStatus(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDataStream(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdFree(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdHostname(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdUser(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdHelp(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdExitServer(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSettingsDir(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTrimEn(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdOutDir(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdFileName(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdRateCorr(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdNetworkParameter(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPort(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdLastClient(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdOnline(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDetectorSize(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSettings(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSN(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDigiTest(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdRegister(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDAC(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTiming(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTimer(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTimeLeft(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSpeed(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdAdvanced(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdConfiguration(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdCounter(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdADC(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTempControl(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdReceiver(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPattern(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPulse(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdProcessor(int narg, const char * const args[], int action, int detPos = -1);
int numberOfCommands;

View File

@ -340,12 +340,12 @@ public:
int64_t setNumberOfFrames(int64_t t = -1, int detPos = -1);
/**
* Set/get number of cycles
* @param t number of cycles (-1 gets)
* Set/get number of triggers
* @param t number of triggers (-1 gets)
* @param detPos -1 for all detectors in list or specific detector position
* @returns number of cycles
* @returns number of triggers
*/
int64_t setNumberOfCycles(int64_t t = -1, int detPos = -1);
int64_t setNumberOfTriggers(int64_t t = -1, int detPos = -1);
/**
* Set/get number of additional storage cells (Jungfrau)

View File

@ -1,54 +1,22 @@
#include "CmdProxy.h"
#include "TimeHelper.h"
#include "ToString.h"
#include "logger.h"
#include "slsDetectorCommand.h"
#include "sls_detector_defs.h"
#include "ToString.h"
#include "TimeHelper.h"
#include "container_utils.h"
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
#define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
auto t = det->GETFCN({det_id}); \
if (args.size() == 0) { \
os << OutString(t) << '\n'; \
} else if (args.size() == 1) { \
os << OutString(t, args[0]) << '\n'; \
} else { \
WrongNumberOfParameters(2); \
} \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() == 1) { \
std::string time_str(args[0]); \
std::string unit = RemoveUnit(time_str); \
auto t = StringTo<time::ns>(time_str, unit); \
det->SETFCN(t, {det_id}); \
} else if (args.size() == 2) { \
auto t = StringTo<time::ns>(args[0], args[1]); \
det->SETFCN(t, {det_id}); \
} else { \
WrongNumberOfParameters(2); \
} \
os << args << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str();
#include <iomanip>
namespace sls {
using defs = slsDetectorDefs;
std::ostream &operator<<(std::ostream &os,
const std::vector<std::string> &vec) {
if (!vec.empty()) {
@ -121,26 +89,8 @@ void CmdProxy::WrongNumberOfParameters(size_t expected) {
* *
************************************************/
std::string CmdProxy::Period(int action) {
TIME_COMMAND(getPeriod, setPeriod,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the period");
}
std::string CmdProxy::Exptime(int action) {
TIME_COMMAND(
getExptime, setExptime,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the exposure time");
}
std::string CmdProxy::SubExptime(int action) {
TIME_COMMAND(getSubExptime, setSubExptime,
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the "
"exposure time of EIGER subframes");
}
std::string CmdProxy::ListCommands(int action) {
if (action == slsDetectorDefs::HELP_ACTION)
if (action == defs::HELP_ACTION)
return "list\n\tlists all available commands, list deprecated - "
"list deprecated commands\n";
@ -181,7 +131,243 @@ std::string CmdProxy::ListCommands(int action) {
}
}
/* configuration */
std::string CmdProxy::Hostname(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\tFrees shared memory and sets hostname (or IP address) of all modules concatenated by +." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getHostname({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() < 1) {
WrongNumberOfParameters(1);
}
if (det_id != -1) {
throw sls::RuntimeError("Cannot execute this at module level");
}
// only args[0], but many hostames concatenated with +
if (args[0].find('+') != std::string::npos) {
auto t = sls::split(args[0], '+');
det->setHostname(t);
os << ToString(t) << '\n';
}
// either hostnames separated by space, or single hostname
else {
det->setHostname(args);
os << ToString(args) << '\n';
}
auto t = det->getHostname({det_id});
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::FirmwareVersion(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\tFimware version of detector in format [0xYYMMDD] or integer for Eiger." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getFirmwareVersion({det_id});
if (det->getDetectorType().squash() == defs::EIGER) {
os << OutString(t) << '\n';
} else {
os << OutStringHex(t) << '\n';
}
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Versions(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\tPrint all versions and detector type" << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getFirmwareVersion();
os << "\nDetector Type: " << OutString(det->getDetectorType())
<< "\nPackage Version: " << det->getPackageVersion()
<< std::hex
<< "\nClient Version: 0x" << det->getClientVersion();
if (det->getDetectorType().squash() == defs::EIGER) {
os << "\nFirmware Version: " << OutString(t);
} else {
os << "\nFirmware Version: " << OutStringHex(t);
}
os << "\nDetector Server Version: " << OutStringHex(det->getDetectorServerVersion());
if (det->getUseReceiverFlag().squash(true)) {
os << "\nReceiver Version: " << OutStringHex(det->getReceiverVersion());
}
os << std::dec << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::PackageVersion(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\tPackage version (git branch)." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
os << det->getPackageVersion() << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ClientVersion(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\tClient software version in format [0xYYMMDD]." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
os << ToStringHex(det->getClientVersion()) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DetectorSize(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[nx] [ny]\n\tDetector size, ie. Number of channels in x and y dim. If 0, then hostname adds all modules in y dim. This is used to calculate module coordinates included in UDP data packet header." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getDetectorSize();
os << "[" << t.x << "," << t.y << "]\n";
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
defs::xy t;
t.x = std::stoi(args[0]);
t.y = std::stoi(args[1]);
det->setDetectorSize(t);
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* acquisition parameters */
std::string CmdProxy::Speed(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0 or full_speed|1 or half_speed|2 or quarter_speed]\n\t[Eiger][Jungfrau] Readout speed of chip.\n\tJungfrau also overwrites adcphase to recommended default. " << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getSpeed({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
defs::speedLevel t;
try{
int ival = std::stoi(args[0]);
switch (ival) {
case 0:
t = defs::FULL_SPEED;
break;
case 1:
t = defs::HALF_SPEED;
break;
case 2:
t = defs::QUARTER_SPEED;
break;
default:
throw sls::RuntimeError("Unknown speed " + args[0]);
}
} catch (...) {
t = sls::StringTo<defs::speedLevel>(args[0]);
}
det->setSpeed(t, {det_id});
os << sls::ToString(t) << '\n'; // no args to convert 0,1,2 as well
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Adcphase(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_value] [(optional)deg]\n\t[Jungfrau][Ctb][Gotthard] Phase shift of ADC clock. \n\t[Jungfrau] Absolute phase shift. If deg used, then shift in degrees. Changing Speed also resets adcphase to recommended defaults.\n\t[Ctb] Absolute phase shift. If deg used, then shift in degrees. Changing adcclk also resets adcphase and sets it to previous values.\n\t[Gotthard] Relative phase shift" << '\n';
} else if (action == defs::GET_ACTION) {
Result<int> t;
if (args.size() == 0) {
t = det->getADCPhase({det_id});
os << OutString(t) << '\n';
} else if (args.size() == 1) {
if (args[0] != "deg") {
throw sls::RuntimeError("Unknown adcphase argument " + args[0] + ". Did you mean deg?");
}
t = det->getADCPhaseInDegrees({det_id});
os << OutString(t) << " deg\n";
} else {
WrongNumberOfParameters(0);
}
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setADCPhase(std::stoi(args[0]), {det_id});
os << args.front() << '\n';
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw sls::RuntimeError("Unknown adcphase 2nd argument " + args[1] + ". Did you mean deg?");
}
det->setADCPhaseInDegrees(std::stoi(args[0]), {det_id});
os << args[0] << args[1] << '\n';
} else {
WrongNumberOfParameters(1);
}
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ClockFrequency(int action) {
std::ostringstream os;
@ -199,7 +385,6 @@ std::string CmdProxy::ClockFrequency(int action) {
WrongNumberOfParameters(2);
}
det->setClockFrequency(std::stoi(args[0]), std::stoi(args[1]));
//TODO print args
os << std::stoi(args[1]) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -280,11 +465,593 @@ std::string CmdProxy::ClockDivider(int action) {
WrongNumberOfParameters(2);
}
det->setClockDivider(std::stoi(args[0]), std::stoi(args[1]));
//TODO print args
os << std::stoi(args[1]) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* acquisition */
/* Network Configuration (Detector<->Receiver) */
/* Receiver Config */
/* File */
/* ZMQ Streaming Parameters (Receiver<->Client) */
/* Eiger Specific */
std::string CmdProxy::DynamicRange(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[4|8|16|32]\n\t[Eiger] Dynamic Range or number of bits per pixel in detector." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getDynamicRange({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError("Cannot execute dynamic range at module level");
}
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setDynamicRange(std::stoi(args[0]));
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Threshold(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[eV] [(optinal settings) standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2]\n\t[Eiger] Threshold in eV" << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getThresholdEnergy();
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setThresholdEnergy(std::stoi(args[0]), slsDetectorDefs::GET_SETTINGS, true, {det_id});
} else if (args.size() == 2) {
det->setThresholdEnergy(std::stoi(args[0]), sls::StringTo<slsDetectorDefs::detectorSettings>(args[1]), true, {det_id});
} else {
WrongNumberOfParameters(1);
}
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ThresholdNoTb(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[eV] [(optional settings) standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2]\n\t[Eiger] Threshold in eV set without setting trimbits" << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setThresholdEnergy(std::stoi(args[0]), slsDetectorDefs::GET_SETTINGS, false, {det_id});
} else if (args.size() == 2) {
det->setThresholdEnergy(std::stoi(args[0]), sls::StringTo<slsDetectorDefs::detectorSettings>(args[1]), false, {det_id});
} else {
WrongNumberOfParameters(1);
}
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::GapPixels(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0, 1]\n\t[Eiger] Include Gap pixels in data file or data call back. 4 bit mode gap pixels only ind ata call back." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getRxAddGapPixels({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError("Cannot execute dynamic range at module level");
}
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setRxAddGapPixels(std::stoi(args[0]));
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::TrimEnergies(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[trim_ev1] [trim_Ev2 (optional)] [trim_ev3 (optional)] ...\n\t[Eiger] Number of trim energies and list of trim energies, where corresponding default trim files exist in corresponding trim folders." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getTrimEnergies({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() < 1) {
WrongNumberOfParameters(1);
}
unsigned int ntrim = args.size();
std::vector<int> t(ntrim);
for (unsigned int i = 0; i < ntrim; ++i) {
t[i] = std::stoi(args[i]);
}
det->setTrimEnergies(t, {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::RateCorrection(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_rate (in ns)]\n\t[Eiger] Dead time correction constant in ns. -1 will set to default tau of settings. 0 will unset rate correction." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getRateCorrection({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
int tau = std::stoi(args[0]);
if (tau == -1) {
det->setDefaultRateCorrection({det_id});
auto t = det->getRateCorrection({det_id});
os << OutString(t) << '\n';
} else {
auto t = StringTo<time::ns>(args[0], "ns");
det->setRateCorrection(t, {det_id});
os << args.front() << "ns\n";
}
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Activate(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0, 1] [(optional) padding|nopadding]\n\t[Eiger] 1 is default. 0 deactivates readout and does not send data. \n\tPadding will pad data files for deactivates readouts." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getActive({det_id});
auto p = det->getRxPadDeactivatedMode({det_id});
Result<std::string> pResult(p.size());
for (unsigned int i = 0; i < p.size(); ++i) {
pResult[i] = p[i] ? "padding" : "nopadding";
}
os << OutString(t) << ' ' << OutString(pResult) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() < 1 || args.size() > 2 ) {
WrongNumberOfParameters(2);
}
int t = std::stoi(args[0]);
det->setActive(t, {det_id});
os << args[0];
if (args.size() == 2) {
bool p = true;
if (args[1] == "nopadding") {
p = false;
} else if (args[1] != "padding") {
throw sls::RuntimeError("Unknown argument for deactivated padding.");
}
det->setRxPadDeactivatedMode(p, {det_id});
os << ' ' << args[1];
}
os << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::PulsePixel(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_times] [x] [y]\n\t[Eiger] Pulse pixel n number of times at coordinates (x, y)." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 3) {
WrongNumberOfParameters(3);
}
int n = std::stoi(args[0]);
defs::xy c;
c.x = std::stoi(args[1]);
c.y = std::stoi(args[2]);
det->pulsePixel(n, c, {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::PulsePixelAndMove(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_times] [x] [y]\n\t[Eiger] Pulse pixel n number of times and moves relatively by (x, y)." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 3) {
WrongNumberOfParameters(3);
}
int n = std::stoi(args[0]);
defs::xy c;
c.x = std::stoi(args[1]);
c.y = std::stoi(args[2]);
det->pulsePixelNMove(n, c, {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::PulseChip(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_times] \n\t[Eiger] Pulse chip n times. If n is -1, resets to normal mode (reset chip completely at start of acquisition, where partialreset = 0)." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->pulseChip(std::stoi(args[0]), {det_id});
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Quad(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0, 1]\n\t[Eiger] 0 is default. 1 sets detector size to a quad (Specific hardware required)." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getQuad({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError("Cannot execute dynamic range at module level");
}
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setQuad(std::stoi(args[0]));
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Jungfrau Specific */
std::string CmdProxy::TemperatureEvent(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0]\n\t[Jungfrau] 1, if a temperature event occured. To clear this event, set it to 0.\n\tIf temperature crosses threshold temperature and temperature control is enabled, power to chip will be switched off and temperature event occurs. To power on chip again, temperature has to be less than threshold temperature and temperature event has to be cleared." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getTemperatureEvent({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
if (std::stoi(args[1]) != 0) {
throw sls::RuntimeError("Unknown argument for temp event. Did you mean 0 to reset event?");
}
det->resetTemperatureEvent();
os << "cleared" << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Gotthard Specific */
std::string CmdProxy::ROI(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[xmin] [xmax] \n\t[Gotthard] Region of interest in detector. Either all channels or a single adc or 2 chips (256 channels). Default is all channels enabled (-1 -1). " << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getROI({det_id});
for (auto &it : t) {
os << '[' << it.xmin << ", " << it.xmax << "] \n";
}
} else if (action == defs::PUT_ACTION) {
if (det_id == -1) {
throw sls::RuntimeError("Cannot execute ROI at multi module level");
}
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
defs::ROI t;
t.xmin = std::stoi(args[0]);
t.xmax = std::stoi(args[1]);
det->setROI(t, det_id);
os << '[' << t.xmin << ", " << t.xmax << "] \n";
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ClearROI(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "\n\t[Gotthard] Resets Region of interest in detector. All channels enabled. Default is all channels." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("Cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
det->clearROI({det_id});
os << "[-1, -1] \n";
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Gotthard2 Specific */
/* CTB Specific */
std::string CmdProxy::Samples(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_samples]\n\t[CTB] Number of samples (both analog and digitial) expected." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto a = det->getNumberOfAnalogSamples({det_id});
auto d = det->getNumberOfDigitalSamples({det_id});
int as = a.squash(-1);
int ds = d.squash(-1);
if (as == -1 || ds == -1 || as != ds) { // check if a == d?
throw sls::RuntimeError("Different samples. Use asamples or dsamples.");
}
os << OutString(a) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setNumberOfAnalogSamples(std::stoi(args[0]));
det->setNumberOfDigitalSamples(std::stoi(args[0]));
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Dbitphase(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_value] [(optional)deg]\n\t[Ctb] Phase shift of clock to latch digital bits. Absolute phase shift. If deg used, then shift in degrees. Changing dbitclk also resets dbitphase and sets to previous values." << '\n';
} else if (action == defs::GET_ACTION) {
Result<int> t;
if (args.size() == 0) {
t = det->getDBITPhase({det_id});
os << OutString(t) << '\n';
} else if (args.size() == 1) {
if (args[0] != "deg") {
throw sls::RuntimeError("Unknown dbitphase argument " + args[0] + ". Did you mean deg?");
}
t = det->getDBITPhaseInDegrees({det_id});
os << OutString(t) << " deg\n";
} else {
WrongNumberOfParameters(0);
}
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setDBITPhase(std::stoi(args[0]), {det_id});
os << args.front() << '\n';
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw sls::RuntimeError("Unknown dbitphase 2nd argument " + args[1] + ". Did you mean deg?");
}
det->setDBITPhaseInDegrees(std::stoi(args[0]), {det_id});
os << args[0] << args[1] << '\n';
} else {
WrongNumberOfParameters(1);
}
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::SlowAdc(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_channel (0-7 for channel|8 for temperature)]\n\t[Ctb] Slow ADC channel." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(0);
}
int nchan = std::stoi(args[0]);
if (nchan < 0 || nchan > defs::SLOW_ADC_TEMP - defs::SLOW_ADC0) {
throw sls::RuntimeError("Unknown adc argument " + args[0]);
}
if (nchan == 8) {
auto t = det->getTemperature(defs::SLOW_ADC_TEMP, {det_id});
os << OutString(t) << " °C\n";
} else {
auto t = det->getSlowADC(static_cast<defs::dacIndex>(nchan + defs::SLOW_ADC0));
os << OutString(t) << '\n';
}
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ReceiverDbitList(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[all] or [i0] [i1] [i2]... \n\t[Ctb] List of digital signal bits read out. If all is used instead of a list, all digital bits (64) enabled. Each element in list can be 0 - 63 and non repetitive." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getRxDbitList({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() < 1) {
WrongNumberOfParameters(1);
}
std::vector<int> t;
if (args[0] == "all") {
t.resize(64);
for (unsigned int i = 0; i < 64; ++i) {
t[i] = i;
}
} else {
unsigned int ntrim = args.size();
t.resize(ntrim);
for (unsigned int i = 0; i < ntrim; ++i) {
t[i] = std::stoi(args[i]);
}
}
det->setRxDbitList(t, {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DigitalIODelay(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[64 bit bitmask] [0-775]\n\t[Ctb] Delay for digital IO pins selected by the bitmask. Delay is in ps and max of 775 ps. Resolution is 25 ps." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("Cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setDigitalIODelay(std::stoul(args[0]), std::stoi(args[2]));
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Pattern */
std::string CmdProxy::Pattern(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname]\n\t[Ctb] Loads binary pattern file with only pattern words" << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("Cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setPattern(args[0]);
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::PatternWord(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[step or address] [64 bit mask]\n\t[Ctb] 64 bit pattern at address of pattern memory." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getPatternWord(std::stoi(args[0]), {det_id});
os << OutStringHex(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setPatternWord(std::stoi(args[0]), std::stoul(args[1]));
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
} // namespace sls

View File

@ -22,11 +22,7 @@ void Detector::loadConfig(const std::string &fname) {
}
void Detector::loadParameters(const std::string &fname) {
pimpl->retrieveDetectorSetup(fname, 0);
}
void Detector::savePattern(const std::string &fname) {
pimpl->savePattern(fname);
pimpl->loadParameters(fname);
}
Result<std::string> Detector::getHostname(Positions pos) const {
@ -39,6 +35,14 @@ void Detector::setHostname(const std::vector<std::string> &value) {
int Detector::getShmId() const { return pimpl->getMultiId(); }
std::string Detector::getPackageVersion() const {
return pimpl->getPackageVersion();
}
int64_t Detector::getClientVersion() const {
return pimpl->getClientSoftwareVersion();
}
Result<int64_t> Detector::getFirmwareVersion(Positions pos) const {
return pimpl->Parallel(&slsDetector::getId, pos,
defs::DETECTOR_FIRMWARE_VERSION);
@ -54,10 +58,6 @@ Result<int64_t> Detector::getSerialNumber(Positions pos) const {
defs::DETECTOR_SERIAL_NUMBER);
}
int64_t Detector::getClientVersion() const {
return pimpl->getClientSoftwareVersion();
}
Result<int64_t> Detector::getReceiverVersion(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverSoftwareVersion, pos);
}
@ -117,11 +117,11 @@ void Detector::setNumberOfFrames(int64_t value) {
}
Result<int64_t> Detector::getNumberOfTriggers() const {
return pimpl->Parallel(&slsDetector::setTimer, {}, defs::CYCLES_NUMBER, -1);
return pimpl->Parallel(&slsDetector::setTimer, {}, defs::TRIGGER_NUMBER, -1);
}
void Detector::setNumberOfTriggers(int64_t value) {
pimpl->Parallel(&slsDetector::setTimer, {}, defs::CYCLES_NUMBER, value);
pimpl->Parallel(&slsDetector::setTimer, {}, defs::TRIGGER_NUMBER, value);
}
Result<ns> Detector::getExptime(Positions pos) const {
@ -157,7 +157,7 @@ Result<int64_t> Detector::getNumberOfFramesLeft(Positions pos) const {
}
Result<int64_t> Detector::getNumberOfTriggersLeft(Positions pos) const {
return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::CYCLES_NUMBER);
return pimpl->Parallel(&slsDetector::getTimeLeft, pos, defs::TRIGGER_NUMBER);
}
Result<ns> Detector::getDelayAfterTriggerLeft(Positions pos) const {
@ -246,7 +246,7 @@ Result<int> Detector::getDAC(defs::dacIndex index, bool mV,
return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, mV);
}
void Detector::setDAC(int value, defs::dacIndex index, bool mV, Positions pos) {
void Detector::setDAC(defs::dacIndex index, int value, bool mV, Positions pos) {
pimpl->Parallel(&slsDetector::setDAC, pos, value, index, mV);
}
@ -263,20 +263,27 @@ void Detector::setTimingMode(defs::timingMode value, Positions pos) {
void Detector::acquire() { pimpl->acquire(); }
void Detector::startAcquisition() {
if (getUseReceiverFlag().squash(true))
pimpl->Parallel(&slsDetector::startReceiver, {});
void Detector::clearAcquiringFlag() { pimpl->setAcquiringFlag(0); }
void Detector::startReceiver() {
pimpl->Parallel(&slsDetector::startReceiver, {});
}
void Detector::stopReceiver() {
pimpl->Parallel(&slsDetector::stopReceiver, {});
}
void Detector::startDetector() {
if (getDetectorType({}).squash() == defs::EIGER) {
pimpl->Parallel(&slsDetector::prepareAcquisition, {});
}
pimpl->Parallel(&slsDetector::startAcquisition, {});
}
void Detector::stopAcquisition() {
void Detector::stopDetector() {
pimpl->Parallel(&slsDetector::stopAcquisition, {});
if (getUseReceiverFlag().squash(true))
pimpl->Parallel(&slsDetector::stopReceiver, {});
}
void Detector::clearAcquiringFlag() { pimpl->setAcquiringFlag(0); }
Result<defs::runStatus> Detector::getDetectorStatus(Positions pos) const {
return pimpl->Parallel(&slsDetector::getRunStatus, pos);
}
@ -497,8 +504,19 @@ Result<int> Detector::getRxPort(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverPort, pos);
}
void Detector::setRxPort(int value, Positions pos) {
pimpl->Parallel(&slsDetector::setReceiverPort, pos, value);
void Detector::setRxPort(int port, int module_id) {
if (module_id == -1) {
std::vector<int> port_list(size());
for (auto &it: port_list) {
it = port++;
}
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&slsDetector::setReceiverPort, {idet},
port_list[idet]);
}
} else {
pimpl->Parallel(&slsDetector::setReceiverPort, {module_id}, port);
}
}
Result<int> Detector::getRxFifoDepth(Positions pos) const {
@ -559,7 +577,7 @@ void Detector::setRxLock(bool value, Positions pos) {
pimpl->Parallel(&slsDetector::lockReceiver, pos, static_cast<int>(value));
}
Result<std::string> Detector::getRxLastClientIP(Positions pos) const {
Result<sls::IpAddr> Detector::getRxLastClientIP(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverLastClientIP, pos);
}
@ -589,11 +607,11 @@ void Detector::setFileNamePrefix(const std::string &fname, Positions pos) {
pimpl->Parallel(&slsDetector::setFileName, pos, fname);
}
Result<int> Detector::getAcquisitionIndex(Positions pos) const {
Result<int64_t> Detector::getAcquisitionIndex(Positions pos) const {
return pimpl->Parallel(&slsDetector::getFileIndex, pos);
}
void Detector::setAcquisitionIndex(int i, Positions pos) {
void Detector::setAcquisitionIndex(int64_t i, Positions pos) {
pimpl->Parallel(&slsDetector::setFileIndex, pos, i);
}
@ -675,11 +693,11 @@ void Detector::setRxZmqPort(int port, int module_id) {
}
}
Result<std::string> Detector::getRxZmqIP(Positions pos) const {
Result<IpAddr> Detector::getRxZmqIP(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverStreamingIP, pos);
}
void Detector::setRxZmqIP(const std::string &ip, Positions pos) {
void Detector::setRxZmqIP(const IpAddr ip, Positions pos) {
bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false);
pimpl->Parallel(&slsDetector::setReceiverStreamingIP, pos, ip);
if (previouslyReceiverStreaming) {
@ -705,11 +723,11 @@ void Detector::setClientZmqPort(int port, int module_id) {
}
}
Result<std::string> Detector::getClientZmqIp(Positions pos) const {
Result<IpAddr> Detector::getClientZmqIp(Positions pos) const {
return pimpl->Parallel(&slsDetector::getClientStreamingIP, pos);
}
void Detector::setClientZmqIp(const std::string &ip, Positions pos) {
void Detector::setClientZmqIp(const IpAddr ip, Positions pos) {
int previouslyClientStreaming = pimpl->enableDataStreamingToClient(-1);
pimpl->Parallel(&slsDetector::setClientStreamingIP, pos, ip);
if (previouslyClientStreaming != 0) {
@ -757,11 +775,11 @@ void Detector::setThresholdEnergy(int threshold_ev,
settings, static_cast<int>(trimbits));
}
Result<std::string> Detector::getSettingsDir(Positions pos) const {
Result<std::string> Detector::getSettingsPath(Positions pos) const {
return pimpl->Parallel(&slsDetector::getSettingsDir, pos);
}
void Detector::setSettingsDir(const std::string &value, Positions pos) {
void Detector::setSettingsPath(const std::string &value, Positions pos) {
pimpl->Parallel(&slsDetector::setSettingsDir, pos, value);
}
@ -882,7 +900,12 @@ void Detector::setRxPadDeactivatedMode(bool pad, Positions pos) {
}
Result<bool> Detector::getPartialReset(Positions pos) const {
return pimpl->Parallel(&slsDetector::setCounterBit, pos, -1);
auto res = pimpl->Parallel(&slsDetector::setCounterBit, pos, -1);
Result<bool> t(res.size());
for (unsigned int i = 0; i < res.size(); ++i) {
t[i] = !res[i];
}
return t;
}
void Detector::setPartialReset(bool value, Positions pos) {
@ -943,7 +966,7 @@ Result<bool> Detector::getPowerChip(Positions pos) const {
}
void Detector::setPowerChip(bool on, Positions pos) {
if (on && pimpl->size() > 3) {
if ((pos.empty() || pos[0] == -1) && on && pimpl->size() > 3) {
for (unsigned int i = 0; i != pimpl->size(); ++i) {
pimpl->powerChip(static_cast<int>(on), i);
usleep(1000 * 1000);
@ -996,11 +1019,15 @@ Result<defs::ROI> Detector::getROI(Positions pos) const {
return pimpl->Parallel(&slsDetector::getROI, pos);
}
void Detector::setROI(defs::ROI value, int moduleId) {
if (moduleId < 0 && size() > 1) {
void Detector::setROI(defs::ROI value, int module_id) {
if (module_id < 0 && size() > 1) {
throw RuntimeError("Cannot set ROI for all modules simultaneously");
}
pimpl->Parallel(&slsDetector::setROI, {moduleId}, value);
pimpl->Parallel(&slsDetector::setROI, {module_id}, value);
}
void Detector::clearROI(Positions pos) {
pimpl->Parallel(&slsDetector::clearROI, pos);
}
Result<ns> Detector::getExptimeLeft(Positions pos) const {
@ -1136,14 +1163,6 @@ void Detector::setDBITPipeline(int value, Positions pos) {
pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, value, 0);
}
Result<int> Detector::getVrefVoltage(bool mV, Positions pos) const {
return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::ADC_VPP, mV);
}
void Detector::setVrefVoltage(int value, bool mV, Positions pos) {
pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::ADC_VPP, mV);
}
Result<int> Detector::getVoltage(defs::dacIndex index, Positions pos) const {
switch (index) {
case defs::V_LIMIT:
@ -1160,7 +1179,7 @@ Result<int> Detector::getVoltage(defs::dacIndex index, Positions pos) const {
return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, 1);
}
void Detector::setVoltage(int value, defs::dacIndex index, Positions pos) {
void Detector::setVoltage(defs::dacIndex index, int value, Positions pos) {
switch (index) {
case defs::V_LIMIT:
case defs::V_POWER_A:
@ -1276,6 +1295,10 @@ void Detector::setLEDEnable(bool enable, Positions pos) {
// Pattern
void Detector::savePattern(const std::string &fname) {
pimpl->savePattern(fname);
}
void Detector::setPattern(const std::string &fname, Positions pos) {
pimpl->Parallel(&slsDetector::setPattern, pos, fname);
}
@ -1296,6 +1319,10 @@ void Detector::setPatternClockControl(uint64_t word, Positions pos) {
pimpl->Parallel(&slsDetector::setPatternClockControl, pos, word);
}
Result<uint64_t> Detector::getPatternWord(int addr, Positions pos) {
return pimpl->Parallel(&slsDetector::setPatternWord, pos, addr, -1);
}
void Detector::setPatternWord(int addr, uint64_t word, Positions pos) {
pimpl->Parallel(&slsDetector::setPatternWord, pos, addr, word);
}
@ -1369,7 +1396,7 @@ Result<int> Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax,
Positions pos) const {
auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos,
isEmax ? "emax" : "emin");
Result<int> intResult;
Result<int> intResult(res.size());
try {
for (unsigned int i = 0; i < res.size(); ++i) {
intResult[i] = stoi(res[i]);
@ -1391,7 +1418,7 @@ void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax,
Result<int> Detector::getFrameMode(Positions pos) const {
auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos,
"frameMode");
Result<int> intResult;
Result<int> intResult(res.size());
try {
for (unsigned int i = 0; i < res.size(); ++i) {
intResult[i] = defs::getFrameModeType(res[i]);
@ -1411,7 +1438,7 @@ void Detector::setFrameMode(defs::frameModeType value, Positions pos) {
Result<int> Detector::getDetectorMode(Positions pos) const {
auto res = pimpl->Parallel(&slsDetector::getAdditionalJsonParameter, pos,
"detectorMode");
Result<int> intResult;
Result<int> intResult(res.size());
try {
for (unsigned int i = 0; i < res.size(); ++i) {
intResult[i] = defs::getDetectorModeType(res[i]);
@ -1516,7 +1543,7 @@ void Detector::setDetectorLock(bool lock, Positions pos) {
pimpl->Parallel(&slsDetector::lockServer, pos, static_cast<int>(lock));
}
Result<std::string> Detector::getLastClientIP(Positions pos) const {
Result<sls::IpAddr> Detector::getLastClientIP(Positions pos) const {
return pimpl->Parallel(&slsDetector::getLastClientIP, pos);
}

View File

@ -13,6 +13,7 @@
#include "container_utils.h"
#include "network_utils.h"
#include "string_utils.h"
#include "ToString.h"
#include <cstring>
#include <iomanip>
@ -164,6 +165,8 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) {
return sls::minusOneIfDifferent(r);
}
std::string multiSlsDetector::getPackageVersion() const { return GITBRANCH; }
int64_t multiSlsDetector::getClientSoftwareVersion() const { return APILIB; }
int64_t multiSlsDetector::getReceiverSoftwareVersion(int detPos) {
@ -240,8 +243,7 @@ std::string multiSlsDetector::getUserDetails() {
sstream << "\nType: ";
// get type from multi shm
if (multi_shm()->shmversion >= MULTI_SHMAPIVERSION) {
sstream << slsDetectorDefs::detectorTypeToString(
getDetectorTypeAsEnum());
sstream << ToString(getDetectorTypeAsEnum());
}
// get type from slsdet shm
else {
@ -396,7 +398,10 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
freeSharedMemory();
setupMultiDetector();
}
addMultipleDetectors(name);
for (const auto &hostname : sls::split(name, '+')) {
addSlsDetector(hostname);
}
updateDetectorSize();
}
std::string multiSlsDetector::getHostname(int detPos) const {
@ -410,15 +415,9 @@ std::string multiSlsDetector::getHostname(int detPos) const {
return sls::concatenateNonEmptyStrings(r);
}
void multiSlsDetector::addMultipleDetectors(const char *name) {
for (const auto &hostname : sls::split(name, '+')) {
addSlsDetector(hostname);
}
updateDetectorSize();
}
void multiSlsDetector::addSlsDetector(const std::string &hostname) {
FILE_LOG(logDEBUG1) << "Adding detector " << hostname;
FILE_LOG(logINFO) << "Adding detector " << hostname;
int port = DEFAULT_PORTNO;
std::string host = hostname;
@ -622,13 +621,6 @@ int multiSlsDetector::lockServer(int p, int detPos) {
return sls::minusOneIfDifferent(r);
}
std::string multiSlsDetector::getLastClientIP(int detPos) {
if (detPos >= 0) {
return detectors[detPos]->getLastClientIP();
}
auto r = parallelCall(&slsDetector::getLastClientIP);
return sls::concatenateIfDifferent(r);
}
void multiSlsDetector::exitServer(int detPos) {
if (detPos >= 0) {
@ -650,7 +642,7 @@ void multiSlsDetector::readConfigurationFile(const std::string &fname) {
FILE_LOG(logINFO) << "Loading configuration file: " << fname;
std::ifstream input_file;
input_file.open(fname, std::ios_base::in);
input_file.open(fname.c_str(), std::ios_base::in);
if (!input_file.is_open()) {
throw RuntimeError("Could not open configuration file " + fname +
" for reading");
@ -664,7 +656,7 @@ void multiSlsDetector::readConfigurationFile(const std::string &fname) {
FILE_LOG(logDEBUG1)
<< "current_line after removing comments:\n\t" << current_line;
if (current_line.length() > 1) {
multiSlsDetectorClient(current_line, PUT_ACTION, this);
multiSlsDetectorClient(current_line, PUT_ACTION, nullptr);
}
}
input_file.close();
@ -787,118 +779,6 @@ void multiSlsDetector::saveSettingsFile(const std::string &fname, int detPos) {
parallelCall(&slsDetector::saveSettingsFile, fname);
}
slsDetectorDefs::runStatus multiSlsDetector::getRunStatus(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getRunStatus();
}
// multi
auto r = parallelCall(&slsDetector::getRunStatus);
if (sls::allEqual(r)) {
return r.front();
}
if (sls::anyEqualTo(r, ERROR)) {
return ERROR;
}
for (const auto &value : r) {
if (value != IDLE) {
return value;
}
}
return IDLE;
}
void multiSlsDetector::prepareAcquisition(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->prepareAcquisition();
}
// multi
parallelCall(&slsDetector::prepareAcquisition);
}
void multiSlsDetector::startAcquisition(int detPos) {
// single
if (detPos >= 0) {
if (detectors[detPos]->getDetectorTypeAsEnum() == EIGER) {
detectors[detPos]->prepareAcquisition();
}
detectors[detPos]->startAcquisition();
}
// multi
if (getDetectorTypeAsEnum() == EIGER) {
prepareAcquisition();
}
parallelCall(&slsDetector::startAcquisition);
}
void multiSlsDetector::stopAcquisition(int detPos) {
if (detPos >= 0) {
detectors[detPos]->stopAcquisition();
} else {
parallelCall(&slsDetector::stopAcquisition);
}
}
void multiSlsDetector::sendSoftwareTrigger(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->sendSoftwareTrigger();
}
// multi
parallelCall(&slsDetector::sendSoftwareTrigger);
}
void multiSlsDetector::startAndReadAll(int detPos) {
// single
if (detPos >= 0) {
if (detectors[detPos]->getDetectorTypeAsEnum() == EIGER) {
detectors[detPos]->prepareAcquisition();
}
detectors[detPos]->startAndReadAll();
}
// multi
if (getDetectorTypeAsEnum() == EIGER) {
prepareAcquisition();
}
parallelCall(&slsDetector::startAndReadAll);
}
void multiSlsDetector::startReadOut(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->startReadOut();
}
// multi
parallelCall(&slsDetector::startReadOut);
}
void multiSlsDetector::readAll(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->readAll();
}
// multi
parallelCall(&slsDetector::readAll);
}
/*
void multiSlsDetector::configureMAC(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->configureMAC();
}
// multi
parallelCall(&slsDetector::configureMAC);
}
*/
void multiSlsDetector::setStartingFrameNumber(const uint64_t value,
int detPos) {
@ -994,8 +874,8 @@ int64_t multiSlsDetector::setNumberOfFrames(int64_t t, int detPos) {
return setTimer(FRAME_NUMBER, t, detPos);
}
int64_t multiSlsDetector::setNumberOfCycles(int64_t t, int detPos) {
return setTimer(CYCLES_NUMBER, t, detPos);
int64_t multiSlsDetector::setNumberOfTriggers(int64_t t, int detPos) {
return setTimer(TRIGGER_NUMBER, t, detPos);
}
int64_t multiSlsDetector::setNumberOfStorageCells(int64_t t, int detPos) {
@ -1436,74 +1316,6 @@ int multiSlsDetector::getReceiverStreamingPort(int detPos) {
return sls::minusOneIfDifferent(r);
}
void multiSlsDetector::setClientDataStreamingInIP(const std::string &ip,
int detPos) {
if (ip.length() != 0u) {
bool prev_streaming = enableDataStreamingToClient(-1);
// single
if (detPos >= 0) {
detectors[detPos]->setClientStreamingIP(ip);
}
// multi
else {
for (auto &d : detectors) {
d->setClientStreamingIP(ip);
}
}
if (prev_streaming) {
enableDataStreamingToClient(0);
enableDataStreamingToClient(1);
}
}
}
std::string multiSlsDetector::getClientStreamingIP(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getClientStreamingIP();
}
// multi
auto r = serialCall(&slsDetector::getClientStreamingIP);
return sls::concatenateIfDifferent(r);
}
void multiSlsDetector::setReceiverDataStreamingOutIP(const std::string &ip,
int detPos) {
if (ip.length() != 0u) {
int prev_streaming = enableDataStreamingFromReceiver(-1, detPos);
// single
if (detPos >= 0) {
detectors[detPos]->setReceiverStreamingIP(ip);
}
// multi
else {
for (auto &d : detectors) {
d->setReceiverStreamingIP(ip);
}
}
if (prev_streaming != 0) {
enableDataStreamingFromReceiver(0, detPos);
enableDataStreamingFromReceiver(1, detPos);
}
}
}
std::string multiSlsDetector::getReceiverStreamingIP(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getReceiverStreamingIP();
}
// multi
auto r = serialCall(&slsDetector::getReceiverStreamingIP);
return sls::concatenateIfDifferent(r);
}
int multiSlsDetector::setDetectorNetworkParameter(networkParameter index,
int value, int detPos) {
// single
@ -2209,16 +2021,7 @@ int multiSlsDetector::lockReceiver(int lock, int detPos) {
return sls::minusOneIfDifferent(r);
}
std::string multiSlsDetector::getReceiverLastClientIP(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getReceiverLastClientIP();
}
// multi
auto r = parallelCall(&slsDetector::getReceiverLastClientIP);
return sls::concatenateIfDifferent(r);
}
void multiSlsDetector::exitReceiver(int detPos) {
// single
@ -2360,7 +2163,7 @@ slsDetectorDefs::fileFormat multiSlsDetector::setFileFormat(fileFormat f,
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::incrementFileIndex(int detPos) {
int64_t multiSlsDetector::incrementFileIndex(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->incrementFileIndex();
@ -2371,7 +2174,7 @@ int multiSlsDetector::incrementFileIndex(int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setFileIndex(int i, int detPos) {
int64_t multiSlsDetector::setFileIndex(int64_t i, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setFileIndex(i);
@ -2382,54 +2185,13 @@ int multiSlsDetector::setFileIndex(int i, int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::getFileIndex(int detPos) const {
int64_t multiSlsDetector::getFileIndex(int detPos) const {
if (detPos >= 0)
return detectors[detPos]->getFileIndex();
auto r = parallelCall(&slsDetector::getFileIndex);
return sls::minusOneIfDifferent(r);
}
void multiSlsDetector::startReceiver(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->startReceiver();
}
// multi
parallelCall(&slsDetector::startReceiver);
}
void multiSlsDetector::stopReceiver(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->stopReceiver();
}
// multi
parallelCall(&slsDetector::stopReceiver);
}
slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getReceiverStatus();
}
// multi
auto r = parallelCall(&slsDetector::getReceiverStatus);
if (sls::allEqual(r)) {
return r.front();
}
if (sls::anyEqualTo(r, ERROR)) {
return ERROR;
}
for (const auto &value : r) {
if (value != IDLE) {
return value;
}
}
return IDLE;
}
int multiSlsDetector::getFramesCaughtByReceiver(int detPos) {
// single
@ -2508,7 +2270,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
try {
zmqSocket.push_back(sls::make_unique<ZmqSocket>(
detectors[iSocket / numSocketsPerDetector]
->getClientStreamingIP()
->getClientStreamingIP().str()
.c_str(),
portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
@ -3245,190 +3007,28 @@ void multiSlsDetector::setDigitalIODelay(uint64_t pinMask, int delay,
parallelCall(&slsDetector::setDigitalIODelay, pinMask, delay);
}
int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
int level) {
int skip = 0;
std::string fname;
std::string str;
std::ifstream infile;
int iargval;
int interrupt = 0;
char *args[10];
char myargs[10][1000];
std::string sargname, sargval;
int iline = 0;
if (level == 2) {
FILE_LOG(logDEBUG1) << "config file read";
fname = fname1 + std::string(".det");
} else {
fname = fname1;
void multiSlsDetector::loadParameters(const std::string &fname) {
std::ifstream input_file;
input_file.open(fname.c_str(), std::ios_base::in);
if (!input_file.is_open()) {
throw RuntimeError("Could not open parameter file " + fname +
" for reading");
}
infile.open(fname.c_str(), std::ios_base::in);
if (infile.is_open()) {
auto cmd = slsDetectorCommand(this);
while (infile.good() and interrupt == 0) {
sargname = "none";
sargval = "0";
getline(infile, str);
iline++;
FILE_LOG(logDEBUG1) << str;
if (str.find('#') != std::string::npos) {
FILE_LOG(logDEBUG1) << "Line is a comment \n" << str;
continue;
} else {
std::istringstream ssstr(str);
iargval = 0;
while (ssstr.good()) {
ssstr >> sargname;
// if (ssstr.good()) {
sls::strcpy_safe(myargs[iargval], sargname.c_str());
args[iargval] = myargs[iargval];
FILE_LOG(logDEBUG1) << args[iargval];
iargval++;
// }
skip = 0;
}
if (level != 2) {
if (std::string(args[0]) == std::string("trimbits")) {
skip = 1;
}
}
if (skip == 0) {
cmd.executeLine(iargval, args, PUT_ACTION);
}
}
iline++;
std::string current_line;
while (input_file.good()) {
getline(input_file, current_line);
if (current_line.find('#') != std::string::npos) {
current_line.erase(current_line.find('#'));
}
infile.close();
} else {
throw RuntimeError("Error opening " + fname + " for reading");
FILE_LOG(logDEBUG1)
<< "current_line after removing comments:\n\t" << current_line;
if (current_line.length() > 1) {
multiSlsDetectorClient(current_line, PUT_ACTION, this);
}
}
FILE_LOG(logDEBUG1) << "Read " << iline << " lines";
return OK;
input_file.close();
}
int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
detectorType type = getDetectorTypeAsEnum();
std::vector<std::string> names;
// common config
names.emplace_back("fname");
names.emplace_back("index");
names.emplace_back("enablefwrite");
names.emplace_back("overwrite");
names.emplace_back("dr");
names.emplace_back("settings");
names.emplace_back("exptime");
names.emplace_back("period");
names.emplace_back("frames");
names.emplace_back("cycles");
names.emplace_back("timing");
switch (type) {
case EIGER:
names.emplace_back("flags");
names.emplace_back("clkdivider");
names.emplace_back("threshold");
names.emplace_back("ratecorr");
names.emplace_back("trimbits");
break;
case GOTTHARD:
names.emplace_back("delay");
break;
case JUNGFRAU:
names.emplace_back("delay");
names.emplace_back("clkdivider");
break;
case CHIPTESTBOARD:
names.emplace_back("dac:0");
names.emplace_back("dac:1");
names.emplace_back("dac:2");
names.emplace_back("dac:3");
names.emplace_back("dac:4");
names.emplace_back("dac:5");
names.emplace_back("dac:6");
names.emplace_back("dac:7");
names.emplace_back("dac:8");
names.emplace_back("dac:9");
names.emplace_back("dac:10");
names.emplace_back("dac:11");
names.emplace_back("dac:12");
names.emplace_back("dac:13");
names.emplace_back("dac:14");
names.emplace_back("dac:15");
names.emplace_back("dac:16");
names.emplace_back("dac:17");
names.emplace_back("dac:18");
names.emplace_back("dac:19");
names.emplace_back("dac:20");
names.emplace_back("dac:21");
names.emplace_back("dac:22");
names.emplace_back("dac:23");
names.emplace_back("adcvpp");
names.emplace_back("adcclk");
names.emplace_back("clkdivider");
names.emplace_back("adcphase");
names.emplace_back("adcpipeline");
names.emplace_back("adcinvert"); //
names.emplace_back("adcdisable");
names.emplace_back("patioctrl");
names.emplace_back("patclkctrl");
names.emplace_back("patlimits");
names.emplace_back("patloop0");
names.emplace_back("patnloop0");
names.emplace_back("patwait0");
names.emplace_back("patwaittime0");
names.emplace_back("patloop1");
names.emplace_back("patnloop1");
names.emplace_back("patwait1");
names.emplace_back("patwaittime1");
names.emplace_back("patloop2");
names.emplace_back("patnloop2");
names.emplace_back("patwait2");
names.emplace_back("patwaittime2");
break;
default:
break;
}
// Workaround to bo able to suplly ecexuteLine with char**
const int n_arguments = 1;
char buffer[1000]; // TODO! this should not be hardcoded!
char *args[n_arguments] = {buffer};
std::string outfname;
if (level == 2) {
writeConfigurationFile(fname + ".config");
outfname = fname + ".det";
} else {
outfname = fname;
}
std::ofstream outfile;
outfile.open(outfname.c_str(), std::ios_base::out);
if (outfile.is_open()) {
auto cmd = slsDetectorCommand(this);
for (auto &name : names) {
sls::strcpy_safe(buffer, name.c_str()); // this is...
outfile << name << " "
<< cmd.executeLine(n_arguments, args, GET_ACTION)
<< std::endl;
}
outfile.close();
} else {
throw RuntimeError("Error opening parameters file " + fname +
" for writing");
}
FILE_LOG(logDEBUG1) << "wrote " << names.size() << " lines to "
<< outfname;
return OK;
}
void multiSlsDetector::registerAcquisitionFinishedCallback(
void (*func)(double, int, void *), void *pArg) {
@ -3455,10 +3055,10 @@ void multiSlsDetector::registerDataCallback(
int multiSlsDetector::setTotalProgress() {
int nf = Parallel(&slsDetector::setTimer, {}, FRAME_NUMBER, -1)
.tsquash("Inconsistent number of frames");
int nc = Parallel(&slsDetector::setTimer, {}, CYCLES_NUMBER, -1)
.tsquash("Inconsistent number of cycles");
int nc = Parallel(&slsDetector::setTimer, {}, TRIGGER_NUMBER, -1)
.tsquash("Inconsistent number of triggers");
if (nf == 0 || nc == 0) {
throw RuntimeError("Number of frames or cycles is 0");
throw RuntimeError("Number of frames or triggers is 0");
}
int ns = 1;
@ -3520,8 +3120,8 @@ int multiSlsDetector::acquire() {
// verify receiver is idle
if (receiver) {
if (getReceiverStatus() != IDLE) {
stopReceiver();
if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) != IDLE) {
Parallel(&slsDetector::stopReceiver, {});
}
}
setTotalProgress();
@ -3535,16 +3135,20 @@ int multiSlsDetector::acquire() {
// start receiver
if (receiver) {
startReceiver();
Parallel(&slsDetector::startReceiver, {});
// let processing thread listen to these packets
sem_post(&sem_newRTAcquisition);
}
startAndReadAll();
// start and read all
if (getDetectorTypeAsEnum() == EIGER) {
Parallel(&slsDetector::prepareAcquisition, {});
}
Parallel(&slsDetector::startAndReadAll, {});
// stop receiver
if (receiver) {
stopReceiver();
Parallel(&slsDetector::stopReceiver, {});
if (dataReady != nullptr) {
sem_wait(&sem_endRTAcquisition); // waits for receiver's
}
@ -3560,7 +3164,12 @@ int multiSlsDetector::acquire() {
dataProcessingThread.join();
if (acquisition_finished != nullptr) {
acquisition_finished(getCurrentProgress(), getRunStatus(),
// same status for all, else error
int status = static_cast<int>(ERROR);
auto t = Parallel(&slsDetector::getRunStatus, {});
if (t.equal())
status = t.front();
acquisition_finished(getCurrentProgress(), status,
acqFinished_p);
}
@ -3597,7 +3206,7 @@ void multiSlsDetector::processData() {
if (fgetc(stdin) == 'q') {
FILE_LOG(logINFO)
<< "Caught the command to stop acquisition";
stopAcquisition();
Parallel(&slsDetector::stopAcquisition, {});
}
}
// get progress

View File

@ -30,7 +30,7 @@ void multiSlsDetectorClient::runCommand() {
action_ = slsDetectorDefs::HELP_ACTION;
bool verify = true;
bool update = true;
if (action_ == slsDetectorDefs::PUT_ACTION && parser.n_arguments() == 0) {
if (action_ == slsDetectorDefs::PUT_ACTION && parser.command().empty()) {
os << "Wrong usage - should be: " << parser.executable()
<< "[id-][pos:]channel arg" << std::endl;
os << std::endl;
@ -77,8 +77,9 @@ void multiSlsDetectorClient::runCommand() {
return;
}
}
if (parser.detector_id() >= static_cast<int>(detPtr->size())) {
os << "position is out of bounds.\n";
os << "position " << parser.detector_id() << " is out of bounds (max " << detPtr->size() << ").\n";
return;
}

View File

@ -7,6 +7,8 @@
#include "sls_detector_exceptions.h"
#include "string_utils.h"
#include "versionAPI.h"
#include "ToString.h"
#include <arpa/inet.h>
#include <array>
#include <bitset>
@ -324,7 +326,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
shm()->timerValue[ACQUISITION_TIME] = 0;
shm()->timerValue[FRAME_PERIOD] = 0;
shm()->timerValue[DELAY_AFTER_TRIGGER] = 0;
shm()->timerValue[CYCLES_NUMBER] = 1;
shm()->timerValue[TRIGGER_NUMBER] = 1;
shm()->timerValue[ACTUAL_TIME] = 0;
shm()->timerValue[MEASUREMENT_TIME] = 0;
shm()->timerValue[PROGRESS] = 0;
@ -419,34 +421,34 @@ int slsDetector::sendModule(sls_detector_module *myMod,
n = client.Send(&(myMod->nchan), sizeof(myMod->nchan));
ts += n;
FILE_LOG(level) << "nchan sent. " << n
<< " bytes. serialno: " << myMod->nchan;
<< " bytes. nchan: " << myMod->nchan;
n = client.Send(&(myMod->nchip), sizeof(myMod->nchip));
ts += n;
FILE_LOG(level) << "nchip sent. " << n
<< " bytes. serialno: " << myMod->nchip;
<< " bytes. nchip: " << myMod->nchip;
n = client.Send(&(myMod->ndac), sizeof(myMod->ndac));
ts += n;
FILE_LOG(level) << "ndac sent. " << n
<< " bytes. serialno: " << myMod->ndac;
<< " bytes. ndac: " << myMod->ndac;
n = client.Send(&(myMod->reg), sizeof(myMod->reg));
ts += n;
FILE_LOG(level) << "reg sent. " << n << " bytes. serialno: " << myMod->reg;
FILE_LOG(level) << "reg sent. " << n << " bytes. reg: " << myMod->reg;
n = client.Send(&(myMod->iodelay), sizeof(myMod->iodelay));
ts += n;
FILE_LOG(level) << "iodelay sent. " << n
<< " bytes. serialno: " << myMod->iodelay;
<< " bytes. iodelay: " << myMod->iodelay;
n = client.Send(&(myMod->tau), sizeof(myMod->tau));
ts += n;
FILE_LOG(level) << "tau sent. " << n << " bytes. serialno: " << myMod->tau;
FILE_LOG(level) << "tau sent. " << n << " bytes. tau: " << myMod->tau;
n = client.Send(&(myMod->eV), sizeof(myMod->eV));
ts += n;
FILE_LOG(level) << "ev sent. " << n << " bytes. serialno: " << myMod->eV;
FILE_LOG(level) << "ev sent. " << n << " bytes. ev: " << myMod->eV;
n = client.Send(myMod->dacs, sizeof(int) * (myMod->ndac));
ts += n;
@ -548,7 +550,7 @@ slsDetectorDefs::detectorType slsDetector::getDetectorTypeAsEnum() const {
}
std::string slsDetector::getDetectorTypeAsString() const {
return slsDetectorDefs::detectorTypeToString(getDetectorTypeAsEnum());
return ToString(getDetectorTypeAsEnum());
}
void slsDetector::updateNumberOfChannels() {
@ -695,8 +697,8 @@ bool slsDetector::lockServer(int lock) {
return (retval == 1 ? true : false);
}
std::string slsDetector::getLastClientIP() {
char retval[INET_ADDRSTRLEN]{};
sls::IpAddr slsDetector::getLastClientIP() {
sls::IpAddr retval = 0u;
FILE_LOG(logDEBUG1) << "Getting last client ip to detector server";
sendToDetector(F_GET_LAST_CLIENT_IP, nullptr, retval);
FILE_LOG(logDEBUG1) << "Last client IP to detector: " << retval;
@ -728,8 +730,8 @@ void slsDetector::updateCachedDetectorVariables() {
FORCE_UPDATE) {
int n = 0, i32 = 0;
int64_t i64 = 0;
char lastClientIP[INET_ADDRSTRLEN] = {0};
n += client.Receive(lastClientIP, sizeof(lastClientIP));
sls::IpAddr lastClientIP = 0u;
n += client.Receive(&lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1)
<< "Updating detector last modified by " << lastClientIP;
@ -787,9 +789,9 @@ void slsDetector::updateCachedDetectorVariables() {
shm()->timerValue[STORAGE_CELL_DELAY] = i64;
}
// cycles
// triggers
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[CYCLES_NUMBER] = i64;
shm()->timerValue[TRIGGER_NUMBER] = i64;
// readout mode
if (shm()->myDetectorType == CHIPTESTBOARD) {
@ -934,7 +936,7 @@ slsDetector::setSettings(detectorSettings isettings) {
return shm()->currentSettings;
default:
std::ostringstream ss;
ss << "Unknown settings " << getDetectorSettings(isettings)
ss << "Unknown settings " << ToString(isettings)
<< " for this detector!";
throw RuntimeError(ss.str());
}
@ -1088,7 +1090,7 @@ std::string slsDetector::getTrimbitFilename(detectorSettings s, int e_eV) {
break;
default:
std::ostringstream ss;
ss << "Unknown settings " << getDetectorSettings(s)
ss << "Unknown settings " << ToString(s)
<< " for this detector!";
throw RuntimeError(ss.str());
}
@ -1146,7 +1148,7 @@ slsDetectorDefs::runStatus slsDetector::getRunStatus() const {
runStatus retval = ERROR;
FILE_LOG(logDEBUG1) << "Getting status";
sendToDetectorStop(F_GET_RUN_STATUS, nullptr, retval);
FILE_LOG(logDEBUG1) << "Detector status: " << runStatusType(retval);
FILE_LOG(logDEBUG1) << "Detector status: " << ToString(retval);
return retval;
}
@ -1202,116 +1204,6 @@ void slsDetector::readAll() {
FILE_LOG(logDEBUG1) << "Detector successfully finished reading all frames";
}
/*
void slsDetector::configureMAC() {
int fnum = F_CONFIGURE_MAC;
const size_t array_size = 50;
const size_t n_args = 14;
const size_t n_retvals = 2;
char args[n_args][array_size]{};
char retvals[n_retvals][array_size]{};
FILE_LOG(logDEBUG1) << "Configuring MAC";
if (shm()->rxUDPIP == 0) {
// If hostname is valid ip use that, oterwise lookup hostname
shm()->rxUDPIP = shm()->rxHostname;
if (shm()->rxUDPIP == 0) {
shm()->rxUDPIP = HostnameToIp(shm()->rxHostname);
}
}
if (shm()->rxUDPMAC == 0) {
throw RuntimeError(
"configureMAC: Error. Receiver UDP MAC Addresses not set");
}
FILE_LOG(logDEBUG1) << "rx_hostname and rx_udpmac are valid ";
// Jungfrau second interface
if (shm()->numUDPInterfaces == 2) {
if (shm()->rxUDPIP2 == 0) {
shm()->rxUDPIP2 = shm()->rxUDPIP;
}
if (shm()->rxUDPMAC2 == 0) {
throw RuntimeError(
"configureMAC: Error. Receiver UDP MAC Addresses 2 not set");
}
FILE_LOG(logDEBUG1) << "rx_udpmac2 is valid ";
}
// copy to args and convert to hex
snprintf(args[0], array_size, "%x", shm()->rxUDPPort);
sls::strcpy_safe(args[1], getReceiverUDPIP().hex());
sls::strcpy_safe(args[2], getReceiverUDPMAC().hex());
sls::strcpy_safe(args[3], getDetectorIP().hex());
sls::strcpy_safe(args[4], getDetectorMAC().hex());
snprintf(args[5], array_size, "%x", shm()->rxUDPPort2);
sls::strcpy_safe(args[6], getReceiverUDPIP2().hex());
sls::strcpy_safe(args[7], getReceiverUDPMAC2().hex());
sls::strcpy_safe(args[8], getDetectorIP2().hex());
sls::strcpy_safe(args[9], getDetectorMAC2().hex());
snprintf(args[10], array_size, "%x", shm()->numUDPInterfaces);
snprintf(args[11], array_size, "%x", shm()->selectedUDPInterface);
// 2d positions to detector to put into udp header
{
int pos[2] = {0, 0};
int max = shm()->multiSize.y * (shm()->numUDPInterfaces);
// row
pos[0] = (detId % max);
// col for horiz. udp ports
pos[1] = (detId / max) * ((shm()->myDetectorType == EIGER) ? 2 : 1);
// pos[2] (z is reserved)
FILE_LOG(logDEBUG) << "Detector [" << detId << "] - (" << pos[0] << ","
<< pos[1] << ")";
snprintf(args[12], array_size, "%x", pos[0]);
snprintf(args[13], array_size, "%x", pos[1]);
}
FILE_LOG(logDEBUG1) << "receiver udp port:" << std::dec << args[0] << "-";
FILE_LOG(logDEBUG1) << "receiver udp ip:" << args[1] << "-";
FILE_LOG(logDEBUG1) << "receiver udp mac:" << args[2] << "-";
FILE_LOG(logDEBUG1) << "detecotor udp ip:" << args[3] << "-";
FILE_LOG(logDEBUG1) << "detector udp mac:" << args[4] << "-";
FILE_LOG(logDEBUG1) << "receiver udp port2:" << std::dec << args[5] << "-";
FILE_LOG(logDEBUG1) << "receiver udp ip2:" << args[6] << "-";
FILE_LOG(logDEBUG1) << "receiver udp mac2:" << args[7] << "-";
FILE_LOG(logDEBUG1) << "detecotor udp ip2:" << args[8] << "-";
FILE_LOG(logDEBUG1) << "detector udp mac2:" << args[9] << "-";
FILE_LOG(logDEBUG1) << "number of udp interfaces:" << std::dec << args[10]
<< "-";
FILE_LOG(logDEBUG1) << "selected udp interface:" << std::dec << args[11]
<< "-";
FILE_LOG(logDEBUG1) << "row:" << args[12] << "-";
FILE_LOG(logDEBUG1) << "col:" << args[13] << "-";
// send to server
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
int ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals,
sizeof(retvals));
// TODO!(Erik) Send as int already from detector
uint64_t detector_mac = 0;
uint32_t detector_ip = 0;
sscanf(retvals[0], "%lx", &detector_mac);
sscanf(retvals[1], "%x", &detector_ip);
detector_ip = __builtin_bswap32(detector_ip);
if (shm()->detectorMAC != detector_mac) {
shm()->detectorMAC = detector_mac;
FILE_LOG(logINFO) << detId << ": Detector MAC updated to "
<< getDetectorMAC();
}
if (shm()->detectorIP != detector_ip) {
shm()->detectorIP = detector_ip;
FILE_LOG(logINFO) << detId << ": Detector IP updated to "
<< getDetectorIP();
}
if (ret == FORCE_UPDATE) {
updateCachedDetectorVariables();
}
}
*/
void slsDetector::setStartingFrameNumber(uint64_t value) {
FILE_LOG(logDEBUG1) << "Setting starting frame number to " << value;
sendToDetector(F_SET_STARTING_FRAME_NUMBER, value, nullptr);
@ -1361,7 +1253,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
if (shm()->useReceiverFlag) {
timerIndex rt[]{FRAME_NUMBER,
FRAME_PERIOD,
CYCLES_NUMBER,
TRIGGER_NUMBER,
ACQUISITION_TIME,
SUBFRAME_ACQUISITION_TIME,
SUBFRAME_DEADTIME,
@ -1376,11 +1268,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
retval = -1;
// rewrite args
if ((index == FRAME_NUMBER) || (index == CYCLES_NUMBER) ||
if ((index == FRAME_NUMBER) || (index == TRIGGER_NUMBER) ||
(index == STORAGE_CELL_NUMBER)) {
args[1] = shm()->timerValue[FRAME_NUMBER] *
((shm()->timerValue[CYCLES_NUMBER] > 0)
? (shm()->timerValue[CYCLES_NUMBER])
((shm()->timerValue[TRIGGER_NUMBER] > 0)
? (shm()->timerValue[TRIGGER_NUMBER])
: 1) *
((shm()->timerValue[STORAGE_CELL_NUMBER] > 0)
? (shm()->timerValue[STORAGE_CELL_NUMBER]) + 1
@ -1388,9 +1280,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
}
FILE_LOG(logDEBUG1)
<< "Sending "
<< (((index == FRAME_NUMBER) || (index == CYCLES_NUMBER) ||
<< (((index == FRAME_NUMBER) || (index == TRIGGER_NUMBER) ||
(index == STORAGE_CELL_NUMBER))
? "(#Frames) * (#cycles) * (#storage cells)"
? "(#Frames) * (#triggers) * (#storage cells)"
: getTimerType(index))
<< " to receiver: " << args[1];
@ -1630,7 +1522,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
FILE_LOG(logDEBUG)
<< "detector type:"
<< (slsDetectorDefs::detectorTypeToString(shm()->myDetectorType))
<< (ToString(shm()->myDetectorType))
<< "\ndetector id:" << detId
<< "\ndetector hostname:" << shm()->hostname
<< "\nfile path:" << shm()->rxFilePath
@ -1645,7 +1537,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
<< "\noverwrite enable:" << shm()->rxFileOverWrite
<< "\nframe index needed:"
<< ((shm()->timerValue[FRAME_NUMBER] *
shm()->timerValue[CYCLES_NUMBER]) > 1)
shm()->timerValue[TRIGGER_NUMBER]) > 1)
<< "\nframe period:" << (shm()->timerValue[FRAME_PERIOD])
<< "\nframe number:" << (shm()->timerValue[FRAME_NUMBER])
<< "\nsub exp time:" << (shm()->timerValue[SUBFRAME_ACQUISITION_TIME])
@ -1745,7 +1637,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
// data streaming
setReceiverStreamingFrequency(shm()->rxReadFreq);
setReceiverStreamingPort(getReceiverStreamingPort());
setReceiverStreamingIP(getReceiverStreamingIP());
updateReceiverStreamingIP();
setAdditionalJsonHeader(shm()->rxAdditionalJsonHeader);
enableDataStreamingFromReceiver(
static_cast<int>(enableDataStreamingFromReceiver(-1)));
@ -1826,7 +1718,7 @@ sls::IpAddr slsDetector::getSourceUDPIP2() {
void slsDetector::setDestinationUDPIP(const IpAddr ip) {
FILE_LOG(logDEBUG1) << "Setting destination udp ip to " << ip;
if (ip == 0) {
if (ip == 0) {
throw RuntimeError("Invalid destination udp ip address");
}
sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr);
@ -2011,31 +1903,23 @@ void slsDetector::setReceiverStreamingPort(int port) {
int slsDetector::getReceiverStreamingPort() { return shm()->rxZmqport; }
void slsDetector::setClientStreamingIP(const std::string &sourceIP) {
auto ip = HostnameToIp(sourceIP.c_str());
if (ip != 0) {
shm()->zmqip = ip;
} else {
throw sls::RuntimeError("Could not set zmqip");
}
void slsDetector::setClientStreamingIP(const sls::IpAddr ip) {
FILE_LOG(logDEBUG1) << "Setting client zmq ip to " << ip;
if (ip == 0) {
throw RuntimeError("Invalid client zmq ip address");
}
shm()->zmqip = ip;
}
std::string slsDetector::getClientStreamingIP() { return shm()->zmqip.str(); }
sls::IpAddr slsDetector::getClientStreamingIP() { return shm()->zmqip; }
void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
// if empty, give rx_hostname
if (sourceIP.empty() || sourceIP == "0.0.0.0") {
if (strcmp(shm()->rxHostname, "none") == 0) {
throw RuntimeError("Receiver hostname not set yet. Cannot create "
"rx_zmqip from none");
}
sourceIP = shm()->rxHostname;
void slsDetector::setReceiverStreamingIP(const sls::IpAddr ip) {
FILE_LOG(logDEBUG1) << "Setting rx zmq ip to " << ip;
if (ip == 0) {
throw RuntimeError("Invalid receiver zmq ip address");
}
FILE_LOG(logDEBUG1) << "Sending receiver streaming IP to receiver: "
<< sourceIP;
shm()->rxZmqip = HostnameToIp(sourceIP.c_str());
shm()->rxZmqip = ip;
// if zmqip is empty, update it
if (shm()->zmqip == 0) {
shm()->zmqip = shm()->rxZmqip;
@ -2043,19 +1927,27 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
// send to receiver
if (shm()->useReceiverFlag) {
char retvals[MAX_STR_LENGTH]{};
char args[MAX_STR_LENGTH]{};
sls::strcpy_safe(args, shm()->rxZmqip.str()); // TODO send int
FILE_LOG(logDEBUG1)
<< "Sending receiver streaming IP to receiver: " << args;
sendToReceiver(F_RECEIVER_STREAMING_SRC_IP, args, retvals);
FILE_LOG(logDEBUG1) << "Receiver streaming ip: " << retvals;
shm()->rxZmqip = retvals;
<< "Sending receiver streaming IP to receiver: " << ip;
sendToReceiver(F_RECEIVER_STREAMING_SRC_IP, ip, nullptr);
}
}
std::string slsDetector::getReceiverStreamingIP() {
return shm()->rxZmqip.str();
sls::IpAddr slsDetector::getReceiverStreamingIP() {
return shm()->rxZmqip;
}
void slsDetector::updateReceiverStreamingIP() {
auto ip = getReceiverStreamingIP();
if (ip == 0) {
// Hostname could be ip try to decode otherwise look up the hostname
ip = shm()->rxHostname;
if (ip == 0) {
ip = HostnameToIp(shm()->rxHostname);
}
FILE_LOG(logINFO) << "Setting default receiver streaming zmq ip to " << ip;
}
setReceiverStreamingIP(ip);
}
int slsDetector::setDetectorNetworkParameter(networkParameter index,
@ -2834,8 +2726,8 @@ int slsDetector::lockReceiver(int lock) {
return retval;
}
std::string slsDetector::getReceiverLastClientIP() const {
char retval[INET_ADDRSTRLEN]{};
sls::IpAddr slsDetector::getReceiverLastClientIP() const {
sls::IpAddr retval = 0u;
FILE_LOG(logDEBUG1) << "Getting last client ip to receiver server";
if (shm()->useReceiverFlag) {
sendToReceiver(F_GET_LAST_RECEIVER_CLIENT_IP, nullptr, retval);
@ -2871,12 +2763,13 @@ void slsDetector::updateCachedReceiverVariables() const {
sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort);
receiver.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
int n = 0, i32 = 0;
int64_t i64 = 0;
char cstring[MAX_STR_LENGTH]{};
char lastClientIP[INET_ADDRSTRLEN]{};
IpAddr ip = 0u;
n += receiver.Receive(lastClientIP, sizeof(lastClientIP));
n += receiver.Receive(&ip, sizeof(ip));
FILE_LOG(logDEBUG1)
<< "Updating receiver last modified by " << lastClientIP;
<< "Updating receiver last modified by " << ip;
// filepath
n += receiver.Receive(cstring, sizeof(cstring));
@ -2887,8 +2780,8 @@ void slsDetector::updateCachedReceiverVariables() const {
sls::strcpy_safe(shm()->rxFileName, cstring);
// index
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFileIndex = i32;
n += receiver.Receive(&i64, sizeof(i64));
shm()->rxFileIndex = i64;
// file format
n += receiver.Receive(&i32, sizeof(i32));
@ -2931,8 +2824,8 @@ void slsDetector::updateCachedReceiverVariables() const {
shm()->rxZmqport = i32;
// streaming source ip
n += receiver.Receive(cstring, sizeof(cstring));
shm()->rxZmqip = cstring;
n += receiver.Receive(&ip, sizeof(ip));
shm()->rxZmqip = ip;
// additional json header
n += receiver.Receive(cstring, sizeof(cstring));
@ -3102,9 +2995,9 @@ slsDetectorDefs::fileFormat slsDetector::getFileFormat() const {
return shm()->rxFileFormat;
}
int slsDetector::setFileIndex(int file_index) {
int64_t slsDetector::setFileIndex(int64_t file_index) {
if (F_SET_RECEIVER_FILE_INDEX >= 0) {
int retval = -1;
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Setting file index to " << file_index;
if (shm()->useReceiverFlag) {
sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, retval);
@ -3115,9 +3008,9 @@ int slsDetector::setFileIndex(int file_index) {
return getFileIndex();
}
int slsDetector::getFileIndex() const { return shm()->rxFileIndex; }
int64_t slsDetector::getFileIndex() const { return shm()->rxFileIndex; }
int slsDetector::incrementFileIndex() {
int64_t slsDetector::incrementFileIndex() {
if (shm()->rxFileWrite) {
return setFileIndex(shm()->rxFileIndex + 1);
}
@ -3143,7 +3036,7 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus() const {
FILE_LOG(logDEBUG1) << "Getting Receiver Status";
if (shm()->useReceiverFlag) {
sendToReceiver(F_GET_RECEIVER_STATUS, nullptr, retval);
FILE_LOG(logDEBUG1) << "Receiver Status: " << runStatusType(retval);
FILE_LOG(logDEBUG1) << "Receiver Status: " << ToString(retval);
}
return retval;
}

File diff suppressed because it is too large Load Diff

View File

@ -143,8 +143,8 @@ int64_t slsDetectorUsers::setNumberOfFrames(int64_t t, int detPos){
return detector.setNumberOfFrames(t, detPos);
}
int64_t slsDetectorUsers::setNumberOfCycles(int64_t t, int detPos){
return detector.setNumberOfCycles(t, detPos);
int64_t slsDetectorUsers::setNumberOfTriggers(int64_t t, int detPos){
return detector.setNumberOfTriggers(t, detPos);
}
int64_t slsDetectorUsers::setNumberOfStorageCells(int64_t t, int detPos) {

File diff suppressed because it is too large Load Diff