From 4259363169a52c06102a39760905eb9d064112ae Mon Sep 17 00:00:00 2001 From: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Date: Wed, 18 May 2022 11:48:38 +0200 Subject: [PATCH] rxr sls namespace (#457) * rxr src files and classes (detectordata, ZmqSocket) added to sls namespace * moving defines inside namespace * moving defines inside namespace, added helpdacs to namespace * added namespace to gui * gui also updated * removed unnecessary sls:: when already in sls namespace for slsDetectoSoftware, receverSoftware, slsDetectorGui and slsSupportlib --- RELEASE.txt | 1 + slsDetectorGui/include/qCloneWidget.h | 4 + slsDetectorGui/include/qDacWidget.h | 8 +- slsDetectorGui/include/qDefs.h | 12 +- slsDetectorGui/include/qDetectorMain.h | 11 +- slsDetectorGui/include/qDrawPlot.h | 11 +- slsDetectorGui/include/qTabAdvanced.h | 8 +- slsDetectorGui/include/qTabDataOutput.h | 8 +- slsDetectorGui/include/qTabDebugging.h | 8 +- slsDetectorGui/include/qTabDeveloper.h | 8 +- slsDetectorGui/include/qTabMeasurement.h | 11 +- slsDetectorGui/include/qTabMessages.h | 4 + slsDetectorGui/include/qTabPlot.h | 8 +- slsDetectorGui/include/qTabSettings.h | 8 +- .../slsDetectorPlotting/include/SlsQt1DPlot.h | 9 +- .../include/SlsQt1DZoomer.h | 4 + .../slsDetectorPlotting/include/SlsQt2DHist.h | 4 + .../slsDetectorPlotting/include/SlsQt2DPlot.h | 4 + .../include/SlsQt2DZoomer.h | 4 + .../slsDetectorPlotting/src/SlsQt1DPlot.cpp | 4 + .../slsDetectorPlotting/src/SlsQt1DZoomer.cpp | 4 + .../slsDetectorPlotting/src/SlsQt2DHist.cpp | 4 + .../slsDetectorPlotting/src/SlsQt2DPlot.cpp | 3 + slsDetectorGui/src/qCloneWidget.cpp | 8 +- slsDetectorGui/src/qDacWidget.cpp | 6 +- slsDetectorGui/src/qDetectorMain.cpp | 26 +- slsDetectorGui/src/qDrawPlot.cpp | 14 +- slsDetectorGui/src/qTabAdvanced.cpp | 18 +- slsDetectorGui/src/qTabDataOutput.cpp | 12 +- slsDetectorGui/src/qTabDebugging.cpp | 10 +- slsDetectorGui/src/qTabDeveloper.cpp | 24 +- slsDetectorGui/src/qTabMeasurement.cpp | 12 +- slsDetectorGui/src/qTabMessages.cpp | 4 + slsDetectorGui/src/qTabPlot.cpp | 6 +- slsDetectorGui/src/qTabSettings.cpp | 22 +- slsDetectorSoftware/include/sls/Detector.h | 6 +- .../include/sls/detectorData.h | 4 + slsDetectorSoftware/src/CmdProxy.cpp | 412 +++++++++--------- slsDetectorSoftware/src/CmdProxy.h | 90 ++-- slsDetectorSoftware/src/Detector.cpp | 18 +- slsDetectorSoftware/src/DetectorImpl.cpp | 36 +- slsDetectorSoftware/src/DetectorImpl.h | 50 +-- slsDetectorSoftware/src/HelpDacs.h | 6 +- slsDetectorSoftware/src/Module.cpp | 114 ++--- slsDetectorSoftware/src/Module.h | 60 +-- slsDetectorSoftware/src/SharedMemory.h | 10 +- slsReceiverSoftware/include/sls/Receiver.h | 3 +- slsReceiverSoftware/src/Arping.cpp | 14 +- slsReceiverSoftware/src/Arping.h | 5 + slsReceiverSoftware/src/BinaryDataFile.cpp | 12 +- slsReceiverSoftware/src/BinaryDataFile.h | 6 +- slsReceiverSoftware/src/ClientInterface.cpp | 104 ++--- slsReceiverSoftware/src/ClientInterface.h | 227 +++++----- slsReceiverSoftware/src/DataProcessor.cpp | 22 +- slsReceiverSoftware/src/DataProcessor.h | 12 +- slsReceiverSoftware/src/DataStreamer.cpp | 10 +- slsReceiverSoftware/src/DataStreamer.h | 12 +- slsReceiverSoftware/src/Fifo.cpp | 12 +- slsReceiverSoftware/src/Fifo.h | 11 +- slsReceiverSoftware/src/File.cpp | 4 + slsReceiverSoftware/src/File.h | 8 +- slsReceiverSoftware/src/GeneralData.h | 8 +- slsReceiverSoftware/src/HDF5DataFile.cpp | 16 +- slsReceiverSoftware/src/HDF5DataFile.h | 6 +- slsReceiverSoftware/src/Implementation.cpp | 132 +++--- slsReceiverSoftware/src/Implementation.h | 23 +- slsReceiverSoftware/src/Listener.cpp | 22 +- slsReceiverSoftware/src/Listener.h | 6 +- slsReceiverSoftware/src/MasterAttributes.cpp | 102 ++--- slsReceiverSoftware/src/MasterAttributes.h | 10 +- slsReceiverSoftware/src/MasterFileUtility.cpp | 26 +- slsReceiverSoftware/src/MasterFileUtility.h | 9 +- slsReceiverSoftware/src/MultiReceiverApp.cpp | 6 +- slsReceiverSoftware/src/Receiver.cpp | 16 +- slsReceiverSoftware/src/ReceiverApp.cpp | 12 +- slsReceiverSoftware/src/ThreadObject.cpp | 6 +- slsReceiverSoftware/src/ThreadObject.h | 4 + slsReceiverSoftware/src/receiver_defs.h | 5 + slsSupportLib/include/sls/StaticVector.h | 2 +- slsSupportLib/include/sls/ToString.h | 4 +- slsSupportLib/include/sls/ZmqSocket.h | 17 +- slsSupportLib/include/sls/logger.h | 5 +- slsSupportLib/src/ClientSocket.cpp | 2 +- slsSupportLib/src/DataSocket.cpp | 4 +- slsSupportLib/src/ServerSocket.cpp | 10 +- slsSupportLib/src/ToString.cpp | 48 +- slsSupportLib/src/ZmqSocket.cpp | 30 +- slsSupportLib/src/file_utils.cpp | 12 +- 88 files changed, 1200 insertions(+), 923 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index bc2a3d528..e5dc14997 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -72,6 +72,7 @@ This document describes the differences between v7.0.0 and v6.x.x - m3 (settings dac check disabled temporarily?) - m3 virtual server sends the right pacets now - gap pixels in gui enabled by default +- rxr src files and classes (detectordata, ZmqSocket, helpDacs) added to sls namespace, and macros (namely from logger (logINFO etc)), slsDetectorGui 2. Resolved Issues ================== diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index ce4484cb6..e078fe890 100644 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -5,6 +5,8 @@ #include #include +namespace sls { + class SlsQtH1D; class SlsQt1DPlot; class SlsQt2DPlot; @@ -43,3 +45,5 @@ class qCloneWidget : public QMainWindow, private Ui::ClonePlotObject { static int NumClones; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qDacWidget.h b/slsDetectorGui/include/qDacWidget.h index ef2b7f85d..55a6df219 100644 --- a/slsDetectorGui/include/qDacWidget.h +++ b/slsDetectorGui/include/qDacWidget.h @@ -6,11 +6,13 @@ #include "ui_form_dac.h" #include +namespace sls { + class qDacWidget : public QWidget, private Ui::WidgetDacObject { Q_OBJECT public: - qDacWidget(QWidget *parent, sls::Detector *detector, bool d, std::string n, + qDacWidget(QWidget *parent, Detector *detector, bool d, std::string n, slsDetectorDefs::dacIndex i); ~qDacWidget(); void SetDetectorIndex(int id); @@ -25,8 +27,10 @@ class qDacWidget : public QWidget, private Ui::WidgetDacObject { void GetAdc(); void Refresh(); - sls::Detector *det; + Detector *det; bool isDac{true}; slsDetectorDefs::dacIndex index; int detectorIndex{-1}; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qDefs.h b/slsDetectorGui/include/qDefs.h index 8ee853bae..c0b269555 100644 --- a/slsDetectorGui/include/qDefs.h +++ b/slsDetectorGui/include/qDefs.h @@ -14,6 +14,8 @@ #include #include +namespace sls { + using std::chrono::duration; using std::chrono::duration_cast; using std::chrono::hours; @@ -47,9 +49,9 @@ class qDefs : public QWidget { static void DisplayExceptions(std::string emsg, std::string src) { try { throw; - } catch (const sls::SocketError &e) { + } catch (const SocketError &e) { throw; - } catch (const sls::SharedMemoryError &e) { + } catch (const SharedMemoryError &e) { throw; } catch (const std::exception &e) { ExceptionMessage(emsg, e.what(), src); @@ -63,9 +65,9 @@ class qDefs : public QWidget { typename NonDeduced::type... Args) { try { throw; - } catch (const sls::SocketError &e) { + } catch (const SocketError &e) { throw; - } catch (const sls::SharedMemoryError &e) { + } catch (const SharedMemoryError &e) { throw; } catch (const std::exception &e) { ExceptionMessage(emsg, e.what(), src); @@ -329,3 +331,5 @@ class qDefs : public QWidget { source); } }; + +} // namespace sls diff --git a/slsDetectorGui/include/qDetectorMain.h b/slsDetectorGui/include/qDetectorMain.h index 2d4b9ac38..6deae929a 100644 --- a/slsDetectorGui/include/qDetectorMain.h +++ b/slsDetectorGui/include/qDetectorMain.h @@ -6,6 +6,11 @@ #include "ui_form_detectormain.h" #include +class QScrollArea; +class QResizeEvent; + +namespace sls { + class qDrawPlot; class qTabMeasurement; class qTabDataOutput; @@ -15,8 +20,6 @@ class qTabSettings; class qTabDebugging; class qTabDeveloper; class qTabMessages; -class QScrollArea; -class QResizeEvent; /** To Over-ride the QTabWidget class to get the tabBar protected * methodTabWidget */ @@ -70,7 +73,7 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject { NumberOfTabs }; slsDetectorDefs::detectorType detType; - std::unique_ptr det; + std::unique_ptr det; qDrawPlot *plot; MyTabWidget *tabs; QScrollArea *scroll[NumberOfTabs]; @@ -88,3 +91,5 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject { QString zoomToolTip; QColor defaultTabColor; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 62acb711e..4a184ca19 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -6,18 +6,21 @@ #include "ui_form_plot.h" #include +class QResizeEvent; + +namespace sls { + class SlsQt1DPlot; class SlsQtH1D; class SlsQt2DPlot; class qCloneWidget; class detectorData; -class QResizeEvent; class qDrawPlot : public QWidget, private Ui::PlotObject { Q_OBJECT public: - qDrawPlot(QWidget *parent, sls::Detector *detector); + qDrawPlot(QWidget *parent, Detector *detector); ~qDrawPlot(); bool GetIsRunning(); void SetRunning(bool enable); @@ -96,7 +99,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { static const int NUM_PEDESTAL_FRAMES = 20; static const int NUM_GOTTHARD25_CHANS = 1280; - sls::Detector *det; + Detector *det; slsDetectorDefs::detectorType detType; SlsQt1DPlot *plot1d{nullptr}; @@ -172,3 +175,5 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { int gainOffset{0}; bool gotthard25; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabAdvanced.h b/slsDetectorGui/include/qTabAdvanced.h index 074ab4131..50379d605 100644 --- a/slsDetectorGui/include/qTabAdvanced.h +++ b/slsDetectorGui/include/qTabAdvanced.h @@ -4,13 +4,15 @@ #include "sls/Detector.h" #include "ui_form_tab_advanced.h" +namespace sls { + class qDrawPlot; class qTabAdvanced : public QWidget, private Ui::TabAdvancedObject { Q_OBJECT public: - qTabAdvanced(QWidget *parent, sls::Detector *detector, qDrawPlot *p); + qTabAdvanced(QWidget *parent, Detector *detector, qDrawPlot *p); ~qTabAdvanced(); public slots: @@ -74,6 +76,8 @@ class qTabAdvanced : public QWidget, private Ui::TabAdvancedObject { void GetExposureTime(); void GetGateDelay(); - sls::Detector *det; + Detector *det; qDrawPlot *plot; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabDataOutput.h b/slsDetectorGui/include/qTabDataOutput.h index bb1fbebe8..0bff14bbf 100644 --- a/slsDetectorGui/include/qTabDataOutput.h +++ b/slsDetectorGui/include/qTabDataOutput.h @@ -4,11 +4,13 @@ #include "sls/Detector.h" #include "ui_form_tab_dataoutput.h" +namespace sls { + class qTabDataOutput : public QWidget, private Ui::TabDataOutputObject { Q_OBJECT public: - qTabDataOutput(QWidget *parent, sls::Detector *detector); + qTabDataOutput(QWidget *parent, Detector *detector); ~qTabDataOutput(); void Refresh(); @@ -39,7 +41,9 @@ class qTabDataOutput : public QWidget, private Ui::TabDataOutputObject { void GetSpeed(); void GetParallel(); - sls::Detector *det; + Detector *det; // Button group for radiobuttons for rate QButtonGroup *btnGroupRate; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabDebugging.h b/slsDetectorGui/include/qTabDebugging.h index 48cd85aae..8d2412237 100644 --- a/slsDetectorGui/include/qTabDebugging.h +++ b/slsDetectorGui/include/qTabDebugging.h @@ -7,11 +7,13 @@ class QTreeWidget; class QTreeWidgetItem; +namespace sls { + class qTabDebugging : public QWidget, private Ui::TabDebuggingObject { Q_OBJECT public: - qTabDebugging(QWidget *parent, sls::Detector *detector); + qTabDebugging(QWidget *parent, Detector *detector); ~qTabDebugging(); void Refresh(); @@ -26,10 +28,12 @@ class qTabDebugging : public QWidget, private Ui::TabDebuggingObject { void Initialization(); void PopulateDetectors(); - sls::Detector *det; + Detector *det; /** Tree Widget displaying the detectors, modules */ QTreeWidget *treeDet; QLabel *lblDetectorHostname; QLabel *lblDetectorFirmware; QLabel *lblDetectorSoftware; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabDeveloper.h b/slsDetectorGui/include/qTabDeveloper.h index 9dacf6442..90b3da3cd 100644 --- a/slsDetectorGui/include/qTabDeveloper.h +++ b/slsDetectorGui/include/qTabDeveloper.h @@ -6,13 +6,15 @@ #include "ui_form_tab_developer.h" #include +namespace sls { + class qDacWidget; class qTabDeveloper : public QWidget, private Ui::TabDeveloperObject { Q_OBJECT public: - qTabDeveloper(QWidget *parent, sls::Detector *detector); + qTabDeveloper(QWidget *parent, Detector *detector); ~qTabDeveloper(); public slots: @@ -29,7 +31,7 @@ class qTabDeveloper : public QWidget, private Ui::TabDeveloperObject { slsDetectorDefs::dacIndex getSLSIndex(slsDetectorDefs::detectorType detType, int index); - sls::Detector *det; + Detector *det; std::vector dacWidgets; std::vector adcWidgets; @@ -38,3 +40,5 @@ class qTabDeveloper : public QWidget, private Ui::TabDeveloperObject { static const int HV_MIN = 60; static const int HV_MAX = 200; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabMeasurement.h b/slsDetectorGui/include/qTabMeasurement.h index 7b1f7d1aa..350a59630 100644 --- a/slsDetectorGui/include/qTabMeasurement.h +++ b/slsDetectorGui/include/qTabMeasurement.h @@ -4,14 +4,17 @@ #include "sls/Detector.h" #include "ui_form_tab_measurement.h" -class qDrawPlot; class QStandardItemModel; +namespace sls { + +class qDrawPlot; + class qTabMeasurement : public QWidget, private Ui::TabMeasurementObject { Q_OBJECT public: - qTabMeasurement(QWidget *parent, sls::Detector *detector, qDrawPlot *p); + qTabMeasurement(QWidget *parent, Detector *detector, qDrawPlot *p); ~qTabMeasurement(); void Refresh(); @@ -81,7 +84,7 @@ class qTabMeasurement : public QWidget, private Ui::TabMeasurementObject { void FileNameChangedSignal(QString); private: - sls::Detector *det; + Detector *det; qDrawPlot *plot; // enum for the timing mode enum { AUTO, TRIGGER, GATED, BURST_TRIGGER, TRIGGER_GATED, NUMTIMINGMODES }; @@ -98,3 +101,5 @@ class qTabMeasurement : public QWidget, private Ui::TabMeasurementObject { int numMeasurements{1}; int currentMeasurement{0}; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabMessages.h b/slsDetectorGui/include/qTabMessages.h index 98676fe24..141c5ec57 100644 --- a/slsDetectorGui/include/qTabMessages.h +++ b/slsDetectorGui/include/qTabMessages.h @@ -6,6 +6,8 @@ class QProcess; class QKeyEvent; +namespace sls { + class qTabMessages : public QWidget, private Ui::TabMessagesObject { Q_OBJECT @@ -34,3 +36,5 @@ class qTabMessages : public QWidget, private Ui::TabMessagesObject { QProcess *process; QStringList lastCommand; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index 073e3a7b3..f57d10b77 100644 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -4,13 +4,15 @@ #include "sls/Detector.h" #include "ui_form_tab_plot.h" +namespace sls { + class qDrawPlot; class qTabPlot : public QWidget, private Ui::TabPlotObject { Q_OBJECT public: - qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p); + qTabPlot(QWidget *parent, Detector *detector, qDrawPlot *p); ~qTabPlot(); void SetScanArgument(); void Refresh(); @@ -53,7 +55,7 @@ class qTabPlot : public QWidget, private Ui::TabPlotObject { void SetXYRange(); void MaintainAspectRatio(int dimension); - sls::Detector *det; + Detector *det; qDrawPlot *plot; bool is1d; @@ -65,3 +67,5 @@ class qTabPlot : public QWidget, private Ui::TabPlotObject { static QString defaultImageYAxisTitle; static QString defaultImageZAxisTitle; }; + +} // namespace sls diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index a2a6ad73e..ef0997c91 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -5,11 +5,13 @@ #include "ui_form_tab_settings.h" #include +namespace sls { + class qTabSettings : public QWidget, private Ui::TabSettingsObject { Q_OBJECT public: - qTabSettings(QWidget *parent, sls::Detector *detector); + qTabSettings(QWidget *parent, Detector *detector); ~qTabSettings(); void Refresh(); public slots: @@ -37,7 +39,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void GetThresholdEnergies(); void GetCounterMask(); - sls::Detector *det; + Detector *det; std::vector counters; enum { @@ -77,3 +79,5 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { DYNAMICRANGE_4 }; }; + +} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h index c71de3f75..7441981db 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h @@ -12,9 +12,12 @@ #include class QPen; -class SlsQt1DPlot; class QwtSymbol; +namespace sls { + +class SlsQt1DPlot; + class SlsQtH1D : public QwtPlotCurve { public: @@ -170,4 +173,8 @@ class SlsQt1DPlot : public QwtPlot { void Update(); }; +} // namespace sls + #endif + + diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DZoomer.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DZoomer.h index c87a37931..19715c92d 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DZoomer.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DZoomer.h @@ -8,6 +8,8 @@ #include #include +namespace sls { + class SlsQtH1D; class SlsQt1DZoomer : public QwtPlotZoomer { @@ -51,4 +53,6 @@ class SlsQt1DZoomer : public QwtPlotZoomer { } }; +} // namespace sls + #endif diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DHist.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DHist.h index e19c1859b..9baacbef6 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DHist.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DHist.h @@ -9,6 +9,8 @@ #include #include +namespace sls { + class SlsQt2DHist : public QwtRasterData { private: @@ -125,4 +127,6 @@ class SlsQt2DHist : public QwtRasterData { } }; +} // namespace sls + #endif diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h index 86531fe99..5b2f499df 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h @@ -12,6 +12,8 @@ class QwtPlotPanner; class QwtScaleWidget; class QwtLinearColorMap; +namespace sls { + class SlsQt2DPlot : public QwtPlot { Q_OBJECT @@ -91,3 +93,5 @@ class SlsQt2DPlot : public QwtPlot { int isLog; QwtPlotShapeItem *roiBox{nullptr}; }; + +} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DZoomer.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DZoomer.h index 227ec0e52..e7b72445d 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DZoomer.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DZoomer.h @@ -7,6 +7,8 @@ #include #include +namespace sls { + class SlsQt2DZoomer : public QwtPlotZoomer { private: SlsQt2DHist *hist; @@ -40,4 +42,6 @@ class SlsQt2DZoomer : public QwtPlotZoomer { } }; +} // namespace sls + #endif diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp index 6d1eef137..3cfa413d4 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp @@ -15,6 +15,8 @@ #include #include +namespace sls { + #define QwtLog10ScaleEngine QwtLogScaleEngine // hmm SlsQtH1D::SlsQtH1D(QString title, int n, double min, double max, double *data) @@ -602,3 +604,5 @@ void SlsQt1DPlot::DisableZoom(bool disable) { } } } + +} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DZoomer.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DZoomer.cpp index 85813fc45..a8a60d43c 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DZoomer.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DZoomer.cpp @@ -7,6 +7,8 @@ #include #include +namespace sls { + void SlsQt1DZoomer::ResetZoomBase() { SetZoomBase(x0, y0, x1 - x0, y1 - y0); // for going between log and nonlog plots @@ -93,3 +95,5 @@ void SlsQt1DZoomer::ExtendZoomBase(SlsQtH1D *h) { ResetZoomBase(); } + +} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp index a6dbf0548..098e2621b 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp @@ -9,6 +9,8 @@ using std::cout; using std::endl; +namespace sls { + SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d, double zmin, double zmax) @@ -143,3 +145,5 @@ double SlsQt2DHist::SetMinimumToFirstGreaterThanZero() { return z_min; } + +} // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp index 5fffaa0e5..4a1f8b687 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp @@ -18,6 +18,8 @@ #include #include +namespace sls { + SlsQt2DPlot::SlsQt2DPlot(QWidget *parent) : QwtPlot(parent) { isLog = 0; axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating); @@ -312,3 +314,4 @@ void SlsQt2DPlot::DisableRoiBox() { } } +} // namespace sls diff --git a/slsDetectorGui/src/qCloneWidget.cpp b/slsDetectorGui/src/qCloneWidget.cpp index 4d8c4210f..2aaba9b92 100644 --- a/slsDetectorGui/src/qCloneWidget.cpp +++ b/slsDetectorGui/src/qCloneWidget.cpp @@ -11,6 +11,8 @@ #include #include +namespace sls { + int qCloneWidget::NumClones{0}; qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot *p1, SlsQt2DPlot *p2, @@ -44,7 +46,7 @@ qCloneWidget::~qCloneWidget() { void qCloneWidget::SetupWidgetWindow(QString title) { std::string winTitle = std::string("Snapshot:") + std::to_string(id) + - std::string(" - ") + sls::Logger::Timestamp(); + std::string(" - ") + Logger::Timestamp(); setWindowTitle(QString(winTitle.c_str())); boxPlot->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal)); @@ -146,4 +148,6 @@ void qCloneWidget::resizeEvent(QResizeEvent *event) { qDefs::DATA_GAIN_PLOT_RATIO); } event->accept(); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorGui/src/qDacWidget.cpp b/slsDetectorGui/src/qDacWidget.cpp index 7fb53b46b..3e47cbe6f 100644 --- a/slsDetectorGui/src/qDacWidget.cpp +++ b/slsDetectorGui/src/qDacWidget.cpp @@ -3,7 +3,9 @@ #include "qDacWidget.h" #include "qDefs.h" -qDacWidget::qDacWidget(QWidget *parent, sls::Detector *detector, bool d, +namespace sls { + +qDacWidget::qDacWidget(QWidget *parent, Detector *detector, bool d, std::string n, slsDetectorDefs::dacIndex i) : QWidget(parent), det(detector), isDac(d), index(i) { setupUi(this); @@ -94,3 +96,5 @@ void qDacWidget::Refresh() { GetAdc(); } } + +} // namespace sls diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 7d136aaba..684122353 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -59,7 +59,7 @@ int main(int argc, char **argv) { case 'f': fname = optarg; - LOG(logDEBUG) << long_options[option_index].name << " " << optarg; + LOG(sls::logDEBUG) << long_options[option_index].name << " " << optarg; break; case 'd': @@ -72,7 +72,7 @@ int main(int argc, char **argv) { case 'v': tempval = APIGUI; - LOG(logINFO) << "SLS Detector GUI " << GITBRANCH << " (0x" + LOG(sls::logINFO) << "SLS Detector GUI " << GITBRANCH << " (0x" << std::hex << tempval << ")"; return 0; @@ -88,7 +88,7 @@ int main(int argc, char **argv) { "i. Default: 0. Required \n" + "\t only when more than one multi " "detector object is needed.\n\n"; - LOG(logERROR) << help_message; + LOG(sls::logERROR) << help_message; return -1; } } @@ -96,16 +96,18 @@ int main(int argc, char **argv) { QApplication app(argc, argv); app.setStyle(new QPlastiqueStyle); // style is deleted by QApplication try { - qDetectorMain det(multiId, fname, isDeveloper); + sls::qDetectorMain det(multiId, fname, isDeveloper); det.show(); app.exec(); } catch (const std::exception &e) { - qDefs::Message(qDefs::CRITICAL, + sls::qDefs::Message(sls::qDefs::CRITICAL, std::string(e.what()) + "\nExiting Gui :'( ", "main"); } return 0; } +namespace sls { + qDetectorMain::qDetectorMain(int multiId, const std::string &fname, bool isDevel) : QMainWindow(nullptr), detType(slsDetectorDefs::GENERIC), @@ -212,7 +214,7 @@ void qDetectorMain::SetUpWidgetWindow() { void qDetectorMain::SetUpDetector(const std::string &config_file, int multiID) { // instantiate detector and set window title - det = sls::make_unique(multiID); + det = make_unique(multiID); // create messages tab to capture config file loading logs tabMessages = new qTabMessages(this); @@ -238,15 +240,15 @@ void qDetectorMain::SetUpDetector(const std::string &config_file, int multiID) { default: std::ostringstream os; os << det->getHostname() << " has " - << sls::ToString(det->getDetectorType().squash()) + << ToString(det->getDetectorType().squash()) << " detector type (" << std::to_string(detType) << "). Exiting GUI."; std::string errorMess = os.str(); - throw sls::RuntimeError(errorMess.c_str()); + throw RuntimeError(errorMess.c_str()); } std::ostringstream os; os << "SLS Detector GUI : " - << sls::ToString(det->getDetectorType().squash()) << " - " + << ToString(det->getDetectorType().squash()) << " - " << det->getHostname(); std::string title = os.str(); LOG(logINFO) << title; @@ -441,10 +443,10 @@ void qDetectorMain::ExecuteHelp(QAction *action) { LOG(logINFO) << "About Common GUI for Jungfrau, Eiger, Mythen3, " "Gotthard, Gotthard2 and Moench detectors"; - std::string guiVersion = sls::ToStringHex(APIGUI); + std::string guiVersion = ToStringHex(APIGUI); std::string clientVersion = "unknown"; try { - clientVersion = sls::ToStringHex(det->getClientVersion()); + clientVersion = ToStringHex(det->getClientVersion()); } CATCH_DISPLAY("Could not get client version.", "qDetectorMain::ExecuteHelp") @@ -609,3 +611,5 @@ void qDetectorMain::SetZoomToolTip(bool disable) { else dockWidgetPlot->setToolTip(zoomToolTip); } + +} // namespace sls diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 49a4401b7..d6abbc9aa 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -14,7 +14,9 @@ #include #include -qDrawPlot::qDrawPlot(QWidget *parent, sls::Detector *detector) +namespace sls { + +qDrawPlot::qDrawPlot(QWidget *parent, Detector *detector) : QWidget(parent), det(detector) { setupUi(this); SetupWidgetWindow(); @@ -728,7 +730,7 @@ void qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { progress = currentProgress; std::string status = - sls::ToString(static_cast(detectorStatus)); + ToString(static_cast(detectorStatus)); if (detectorStatus == slsDetectorDefs::ERROR) { qDefs::Message(qDefs::WARNING, @@ -761,7 +763,7 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, << " \t dynamic range: " << data->dynamicRange << std::endl << " \t file index: " << data->fileIndex << std::endl << " \t complete image: " << data->completeImage << std::endl - << " \t rx Roi: " << sls::ToString(data->rxRoi) << std::endl + << " \t rx Roi: " << ToString(data->rxRoi) << std::endl << " ]"; progress = data->progressIndex; @@ -780,9 +782,9 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, rxRoi.xmax += ((rxRoi.xmax/1024) * 6 + (rxRoi.xmax/256) * 2); rxRoi.ymin += ((rxRoi.ymin/512) * 34 + (rxRoi.ymin/256) * 2); rxRoi.ymax += ((rxRoi.ymax/512) * 34 + (rxRoi.ymax/256) * 2); - LOG(logINFO) << "Rx_roi recalculated with gap pixels: " << sls::ToString(rxRoi); + LOG(logINFO) << "Rx_roi recalculated with gap pixels: " << ToString(rxRoi); } - LOG(logDEBUG) << "Rx_roi: " << sls::ToString(rxRoi); + LOG(logDEBUG) << "Rx_roi: " << ToString(rxRoi); } @@ -1272,3 +1274,5 @@ void qDrawPlot::UpdatePlot() { LOG(logDEBUG) << "End of Update Plot"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index 35792344b..433195756 100644 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -5,7 +5,9 @@ #include "qDrawPlot.h" #include "sls/network_utils.h" -qTabAdvanced::qTabAdvanced(QWidget *parent, sls::Detector *detector, +namespace sls { + +qTabAdvanced::qTabAdvanced(QWidget *parent, Detector *detector, qDrawPlot *p) : QWidget(parent), det(detector), plot(p) { setupUi(this); @@ -443,7 +445,7 @@ void qTabAdvanced::SetDetectorUDPIP(bool force) { std::string s = dispDetectorUDPIP->text().toAscii().constData(); LOG(logINFO) << "Setting Detector UDP IP:" << s; try { - det->setSourceUDPIP(sls::IpAddr{s}, + det->setSourceUDPIP(IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Detector UDP IP.", @@ -461,7 +463,7 @@ void qTabAdvanced::SetDetectorUDPMAC(bool force) { std::string s = dispDetectorUDPMAC->text().toAscii().constData(); LOG(logINFO) << "Setting Detector UDP MAC:" << s; try { - det->setSourceUDPMAC(sls::MacAddr{s}, + det->setSourceUDPMAC(MacAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Detector UDP MAC.", @@ -489,7 +491,7 @@ void qTabAdvanced::SetCltZMQIP(bool force) { std::string s = dispZMQIP->text().toAscii().constData(); LOG(logINFO) << "Setting Client ZMQ IP:" << s; try { - det->setClientZmqIp(sls::IpAddr{s}, + det->setClientZmqIp(IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Client ZMQ IP.", @@ -547,7 +549,7 @@ void qTabAdvanced::SetRxrUDPIP(bool force) { std::string s = dispRxrUDPIP->text().toAscii().constData(); LOG(logINFO) << "Setting Receiver UDP IP:" << s; try { - det->setDestinationUDPIP(sls::IpAddr{s}, + det->setDestinationUDPIP(IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Receiver UDP IP.", @@ -565,7 +567,7 @@ void qTabAdvanced::SetRxrUDPMAC(bool force) { std::string s = dispRxrUDPMAC->text().toAscii().constData(); LOG(logINFO) << "Setting Receiver UDP MAC:" << s; try { - det->setDestinationUDPMAC(sls::MacAddr{s}, + det->setDestinationUDPMAC(MacAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Receiver UDP MAC.", @@ -593,7 +595,7 @@ void qTabAdvanced::SetRxrZMQIP(bool force) { std::string s = dispRxrZMQIP->text().toAscii().constData(); LOG(logINFO) << "Setting Receiver ZMQ IP:" << s; try { - det->setRxZmqIP(sls::IpAddr{s}, {comboDetector->currentIndex()}); + det->setRxZmqIP(IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE("Could not set Receiver ZMQ IP.", "qTabAdvanced::SetRxrZMQIP", this, @@ -891,3 +893,5 @@ void qTabAdvanced::Refresh() { } LOG(logDEBUG) << "**Updated Advanced Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 171ec7f3e..6d624a82b 100644 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -11,7 +11,9 @@ #include -qTabDataOutput::qTabDataOutput(QWidget *parent, sls::Detector *detector) +namespace sls { + +qTabDataOutput::qTabDataOutput(QWidget *parent, Detector *detector) : QWidget(parent), det(detector), btnGroupRate(nullptr) { setupUi(this); SetupWidgetWindow(); @@ -232,7 +234,7 @@ void qTabDataOutput::GetFileFormat() { comboFileFormat->setCurrentIndex(static_cast(retval)); break; default: - throw sls::RuntimeError(std::string("Unknown file format: ") + + throw RuntimeError(std::string("Unknown file format: ") + std::to_string(static_cast(retval))); } } @@ -339,7 +341,7 @@ void qTabDataOutput::EnableRateCorrection() { LOG(logINFO) << "Disabling Rate correction"; // disable try { - det->setRateCorrection(sls::ns(0)); + det->setRateCorrection(ns(0)); } CATCH_HANDLE("Could not switch off rate correction.", "qTabDataOutput::EnableRateCorrection", this, @@ -357,7 +359,7 @@ void qTabDataOutput::SetRateCorrection() { int64_t deadtime = spinCustomDeadTime->value(); LOG(logINFO) << "Setting Rate Correction with custom dead time: " << deadtime; - det->setRateCorrection(sls::ns(deadtime)); + det->setRateCorrection(ns(deadtime)); } // default dead time else { @@ -442,3 +444,5 @@ void qTabDataOutput::Refresh() { LOG(logDEBUG) << "**Updated DataOutput Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabDebugging.cpp b/slsDetectorGui/src/qTabDebugging.cpp index b995ba65a..b906bdfe6 100644 --- a/slsDetectorGui/src/qTabDebugging.cpp +++ b/slsDetectorGui/src/qTabDebugging.cpp @@ -7,7 +7,9 @@ #include #include -qTabDebugging::qTabDebugging(QWidget *parent, sls::Detector *detector) +namespace sls { + +qTabDebugging::qTabDebugging(QWidget *parent, Detector *detector) : QWidget(parent), det(detector), treeDet(nullptr), lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr), lblDetectorSoftware(nullptr) { @@ -62,7 +64,7 @@ void qTabDebugging::GetDetectorStatus() { LOG(logDEBUG) << "Getting Status"; try { - std::string status = sls::ToString( + std::string status = ToString( det->getDetectorStatus({comboDetector->currentIndex()})[0]); lblStatus->setText(QString(status.c_str()).toUpper()); } @@ -88,7 +90,7 @@ void qTabDebugging::GetInfo() { lblDetectorFirmware->setFixedWidth(100); layout->addWidget(dispFrame, 0, 1); QString detName = - QString(sls::ToString(det->getDetectorType().squash()).c_str()); + QString(ToString(det->getDetectorType().squash()).c_str()); switch (det->getDetectorType().squash()) { @@ -241,3 +243,5 @@ void qTabDebugging::Refresh() { GetDetectorStatus(); LOG(logDEBUG) << "**Updated Debugging Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabDeveloper.cpp b/slsDetectorGui/src/qTabDeveloper.cpp index 0c4a751e3..c8ee4be6e 100644 --- a/slsDetectorGui/src/qTabDeveloper.cpp +++ b/slsDetectorGui/src/qTabDeveloper.cpp @@ -4,7 +4,9 @@ #include "qDacWidget.h" #include "qDefs.h" -qTabDeveloper::qTabDeveloper(QWidget *parent, sls::Detector *detector) +namespace sls { + +qTabDeveloper::qTabDeveloper(QWidget *parent, Detector *detector) : QWidget(parent), det(detector) { setupUi(this); SetupWidgetWindow(); @@ -324,7 +326,7 @@ void qTabDeveloper::GetHighVoltage() { // spinHV if (spinHV->isVisible()) { if (retval != 0 && retval < hvmin && retval > HV_MAX) { - throw sls::RuntimeError(std::string("Unknown High Voltage: ") + + throw RuntimeError(std::string("Unknown High Voltage: ") + std::to_string(retval)); } spinHV->setValue(retval); @@ -354,7 +356,7 @@ void qTabDeveloper::GetHighVoltage() { comboHV->setCurrentIndex(HV_200); break; default: - throw sls::RuntimeError(std::string("Unknown High Voltage: ") + + throw RuntimeError(std::string("Unknown High Voltage: ") + std::to_string(retval)); } } @@ -431,7 +433,7 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 22: return slsDetectorDefs::TEMPERATURE_FPGA; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; @@ -458,7 +460,7 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 9: return slsDetectorDefs::TEMPERATURE_FPGA; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; @@ -484,7 +486,7 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 8: return slsDetectorDefs::TEMPERATURE_ADC; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; @@ -508,7 +510,7 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 7: return slsDetectorDefs::IBIAS_SFP; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; @@ -550,7 +552,7 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 16: return slsDetectorDefs::VTHRESHOLD; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; @@ -586,13 +588,13 @@ qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { case 13: return slsDetectorDefs::VCOM_ADC2; default: - throw sls::RuntimeError(std::string("Unknown dac/adc index") + + throw RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index)); } break; default: - throw sls::RuntimeError(std::string("Unknown detector type")); + throw RuntimeError(std::string("Unknown detector type")); } } @@ -607,3 +609,5 @@ void qTabDeveloper::Refresh() { GetHighVoltage(); LOG(logDEBUG) << "**Updated Developer Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index fe2049010..4e8976219 100644 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -7,7 +7,9 @@ #include #include -qTabMeasurement::qTabMeasurement(QWidget *parent, sls::Detector *detector, +namespace sls { + +qTabMeasurement::qTabMeasurement(QWidget *parent, Detector *detector, qDrawPlot *p) : QWidget(parent), det(detector), plot(p), progressTimer(nullptr) { setupUi(this); @@ -343,7 +345,7 @@ void qTabMeasurement::GetTimingMode() { if (det->getDetectorType().squash() == slsDetectorDefs::MYTHEN3) { auto retvals = det->getTimingMode(); auto is_master = det->getMaster(); - sls::Result masterRetvals; + Result masterRetvals; for (size_t i = 0; i != is_master.size(); ++i) { if (is_master[i]) { masterRetvals.push_back(retvals[i]); @@ -370,7 +372,7 @@ void qTabMeasurement::GetTimingMode() { } break; default: - throw sls::RuntimeError(std::string("Unknown timing mode: ") + + throw RuntimeError(std::string("Unknown timing mode: ") + std::to_string(retval)); } } @@ -407,7 +409,7 @@ void qTabMeasurement::GetBurstMode() { ShowTriggerDelay(); break; default: - throw sls::RuntimeError(std::string("Unknown burst mode: ") + + throw RuntimeError(std::string("Unknown burst mode: ") + std::to_string(retval)); } } @@ -1017,3 +1019,5 @@ void qTabMeasurement::Refresh() { LOG(logDEBUG) << "**Updated Measurement Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabMessages.cpp b/slsDetectorGui/src/qTabMessages.cpp index 8f87d02d7..802b8de07 100644 --- a/slsDetectorGui/src/qTabMessages.cpp +++ b/slsDetectorGui/src/qTabMessages.cpp @@ -11,6 +11,8 @@ #include #include +namespace sls { + qTabMessages::qTabMessages(QWidget *parent) : QWidget(parent) { setupUi(this); SetupWidgetWindow(); @@ -142,3 +144,5 @@ void qTabMessages::Refresh() { dispCommand->clear(); dispCommand->setFocus(); } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index fb1a65d45..5fe1247aa 100644 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -6,6 +6,8 @@ #include #include +namespace sls { + QString qTabPlot::defaultPlotTitle(""); QString qTabPlot::defaultHistXAxisTitle("Channel Number"); QString qTabPlot::defaultHistYAxisTitle("Counts"); @@ -13,7 +15,7 @@ QString qTabPlot::defaultImageXAxisTitle("Pixel"); QString qTabPlot::defaultImageYAxisTitle("Pixel"); QString qTabPlot::defaultImageZAxisTitle("Intensity"); -qTabPlot::qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p) +qTabPlot::qTabPlot(QWidget *parent, Detector *detector, qDrawPlot *p) : QWidget(parent), det(detector), plot(p), is1d(false) { setupUi(this); SetupWidgetWindow(); @@ -797,3 +799,5 @@ void qTabPlot::Refresh() { LOG(logDEBUG) << "**Updated Plot Tab"; } + +} // namespace sls diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 9a3d97132..23a9f28d6 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -6,7 +6,9 @@ #include "sls/bit_utils.h" #include -qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector) +namespace sls { + +qTabSettings::qTabSettings(QWidget *parent, Detector *detector) : QWidget(parent), det(detector) { setupUi(this); SetupWidgetWindow(); @@ -215,7 +217,7 @@ void qTabSettings::GetSettings() { break; default: if ((int)retval < -1 || (int)retval >= comboSettings->count()) { - throw sls::RuntimeError(std::string("Unknown settings: ") + + throw RuntimeError(std::string("Unknown settings: ") + std::to_string(retval)); } comboSettings->setCurrentIndex(retval); @@ -231,7 +233,7 @@ void qTabSettings::SetSettings(int index) { // settings auto val = static_cast(index); try { - LOG(logINFO) << "Setting Settings to " << sls::ToString(val); + LOG(logINFO) << "Setting Settings to " << ToString(val); det->setSettings(val); } CATCH_HANDLE("Could not set settings.", "qTabSettings::SetSettings", this, @@ -250,7 +252,7 @@ void qTabSettings::GetGainMode() { auto retval = det->getGainMode().tsquash( "Inconsistent gain mode for all detectors."); if ((int)retval < 0 || (int)retval >= comboGainMode->count()) { - throw sls::RuntimeError(std::string("Unknown gain mode: ") + + throw RuntimeError(std::string("Unknown gain mode: ") + std::to_string(retval)); } // warning when using fix_g0 and not in export mode @@ -321,7 +323,7 @@ void qTabSettings::GetDynamicRange() { comboDynamicRange->setCurrentIndex(DYNAMICRANGE_4); break; default: - throw sls::RuntimeError(std::string("Unknown dynamic range: ") + + throw RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(retval)); } } @@ -352,7 +354,7 @@ void qTabSettings::SetDynamicRange(int index) { det->setDynamicRange(4); break; default: - throw sls::RuntimeError(std::string("Unknown dynamic range: ") + + throw RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(index)); } } @@ -399,7 +401,7 @@ void qTabSettings::SetThresholdEnergies() { slsDetectorDefs::detectorSettings sett = static_cast( comboSettings->currentIndex()); - LOG(logINFO) << "Setting Threshold Energies to " << sls::ToString(eV) + LOG(logINFO) << "Setting Threshold Energies to " << ToString(eV) << " (eV)"; try { det->setThresholdEnergy(eV, sett); @@ -430,7 +432,7 @@ void qTabSettings::GetCounterMask() { disconnect(chkCounter3, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); try { - auto retval = sls::getSetBits(det->getCounterMask().tsquash( + auto retval = getSetBits(det->getCounterMask().tsquash( "Counter mask is inconsistent for all detectors.")); // default to unchecked for (auto p : counters) { @@ -439,7 +441,7 @@ void qTabSettings::GetCounterMask() { // if retval[i] = 2, chkCounter2 is checked for (auto i : retval) { if (i > 3) { - throw sls::RuntimeError( + throw RuntimeError( std::string("Unknown counter index : ") + std::to_string(static_cast(i))); } @@ -496,3 +498,5 @@ void qTabSettings::Refresh() { LOG(logDEBUG) << "**Updated Settings Tab"; } + +} // namespace sls diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 9adbd3b89..2caea212c 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -10,10 +10,10 @@ #include #include -class detectorData; namespace sls { using ns = std::chrono::nanoseconds; +class detectorData; class DetectorImpl; class MacAddr; class IpAddr; @@ -884,7 +884,7 @@ class Detector { void setRxLock(bool value, Positions pos = {}); /** Client IP Address that last communicated with the receiver */ - Result getRxLastClientIP(Positions pos = {}) const; + Result getRxLastClientIP(Positions pos = {}) const; /** Get thread ids from the receiver in order of [parent, tcp, listener 0, * processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. If @@ -1919,7 +1919,7 @@ class Detector { void setDetectorLock(bool lock, Positions pos = {}); /** Client IP Address that last communicated with the detector */ - Result getLastClientIP(Positions pos = {}) const; + Result getLastClientIP(Positions pos = {}) const; /** Execute a command on the detector server console */ Result executeCommand(const std::string &value, diff --git a/slsDetectorSoftware/include/sls/detectorData.h b/slsDetectorSoftware/include/sls/detectorData.h index 068e839c7..9cd2fcbe8 100644 --- a/slsDetectorSoftware/include/sls/detectorData.h +++ b/slsDetectorSoftware/include/sls/detectorData.h @@ -4,6 +4,8 @@ #include #include +namespace sls { + /** @short data structure to hold the detector data after postprocessing */ @@ -51,3 +53,5 @@ class detectorData { bool completeImage; std::array rxRoi{{-1, -1, -1, -1}}; }; + +} // namespace sls diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 1642cf848..2f62ebbe5 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -48,7 +48,7 @@ void CmdProxy::Call(const std::string &command, if (it != functions.end()) { os << ((*this).*(it->second))(action); } else { - throw sls::RuntimeError( + throw RuntimeError( cmd + " Unknown command, use list to list all commands"); } } @@ -159,11 +159,11 @@ std::string CmdProxy::Hostname(int action) { WrongNumberOfParameters(1); } if (det_id != -1) { - throw sls::RuntimeError("Cannot execute this at module level"); + throw 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], '+'); + auto t = split(args[0], '+'); det->setHostname(t); os << ToString(t) << '\n'; } @@ -173,7 +173,7 @@ std::string CmdProxy::Hostname(int action) { os << ToString(args) << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -187,19 +187,19 @@ std::string CmdProxy::VirtualServer(int action) { "virtual server will have a stop port (control port + 1)" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("cannot get"); + throw RuntimeError("cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { WrongNumberOfParameters(2); } if (det_id != -1) { - throw sls::RuntimeError("Cannot execute this at module level"); + throw RuntimeError("Cannot execute this at module level"); } det->setVirtualDetectorServers(StringTo(args[0]), StringTo(args[1])); - os << sls::ToString(args); + os << ToString(args); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -219,11 +219,11 @@ std::string CmdProxy::Acquire(int action) { << '\n'; } else { if (det->empty()) { - throw sls::RuntimeError( + throw RuntimeError( "This shared memory has no detectors added."); } if (det_id >= 0) { - throw sls::RuntimeError( + throw RuntimeError( "Individual detectors not allowed for readout."); } @@ -260,9 +260,9 @@ std::string CmdProxy::FirmwareVersion(int action) { os << OutStringHex(t) << '\n'; } } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -297,9 +297,9 @@ std::string CmdProxy::Versions(int action) { } os << std::dec << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -315,9 +315,9 @@ std::string CmdProxy::PackageVersion(int action) { } os << det->getPackageVersion() << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -333,9 +333,9 @@ std::string CmdProxy::ClientVersion(int action) { } os << ToStringHex(det->getClientVersion()) << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -365,7 +365,7 @@ std::string CmdProxy::DetectorSize(int action) { det->setDetectorSize(t); os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -390,7 +390,7 @@ std::string CmdProxy::Threshold(int action) { os << '\n'; } else if (action == defs::GET_ACTION) { if (cmd == "thresholdnotb") { - throw sls::RuntimeError("cannot get"); + throw RuntimeError("cannot get"); } if (!args.empty()) { WrongNumberOfParameters(0); @@ -447,7 +447,7 @@ std::string CmdProxy::Threshold(int action) { } os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -476,9 +476,9 @@ std::string CmdProxy::TrimEnergies(int action) { } } det->setTrimEnergies(t, std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -493,7 +493,7 @@ std::string CmdProxy::GapPixels(int action) { << '\n'; } else if (action == defs::GET_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot get gap pixels at module level"); + throw RuntimeError("Cannot get gap pixels at module level"); } if (!args.empty()) { WrongNumberOfParameters(0); @@ -502,7 +502,7 @@ std::string CmdProxy::GapPixels(int action) { os << t << '\n'; } else if (action == defs::PUT_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot add gap pixels at module level"); + throw RuntimeError("Cannot add gap pixels at module level"); } if (args.size() != 1) { WrongNumberOfParameters(1); @@ -510,7 +510,7 @@ std::string CmdProxy::GapPixels(int action) { det->setGapPixelsinCallback(StringTo(args[0])); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -528,7 +528,7 @@ std::string CmdProxy::Exptime(int action) { } else if (cmd == "exptime3") { gateIndex = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } @@ -612,7 +612,7 @@ std::string CmdProxy::Exptime(int action) { os << args[0] << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -634,7 +634,7 @@ std::string CmdProxy::ReadoutSpeed(int action) { } else { defs::detectorType type = det->getDetectorType().squash(); if (type == defs::CHIPTESTBOARD || type == defs::MOENCH) { - throw sls::RuntimeError( + throw RuntimeError( "ReadoutSpeed not implemented. Did you mean runclk?"); } if (action == defs::GET_ACTION) { @@ -647,11 +647,11 @@ std::string CmdProxy::ReadoutSpeed(int action) { if (args.size() != 1) { WrongNumberOfParameters(1); } - defs::speedLevel t = sls::StringTo(args[0]); + defs::speedLevel t = StringTo(args[0]); det->setReadoutSpeed(t, std::vector{det_id}); - os << sls::ToString(t) << '\n'; // no args to convert 0,1,2 as well + os << ToString(t) << '\n'; // no args to convert 0,1,2 as well } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -674,7 +674,7 @@ std::string CmdProxy::Adcphase(int action) { auto det_type = det->getDetectorType().squash(defs::GENERIC); if (det_type == defs::EIGER || det_type == defs::MYTHEN3 || det_type == defs::GOTTHARD2) { - throw sls::RuntimeError( + throw RuntimeError( "adcphase not implemented for this detector"); } if (action == defs::GET_ACTION) { @@ -684,7 +684,7 @@ std::string CmdProxy::Adcphase(int action) { os << OutString(t) << '\n'; } else if (args.size() == 1) { if (args[0] != "deg") { - throw sls::RuntimeError("Unknown adcphase argument " + + throw RuntimeError("Unknown adcphase argument " + args[0] + ". Did you mean deg? "); } @@ -700,7 +700,7 @@ std::string CmdProxy::Adcphase(int action) { os << args.front() << '\n'; } else if (args.size() == 2) { if (args[1] != "deg") { - throw sls::RuntimeError("Unknown adcphase 2nd argument " + + throw RuntimeError("Unknown adcphase 2nd argument " + args[1] + ". Did you mean deg?"); } det->setADCPhaseInDegrees(StringTo(args[0]), @@ -710,7 +710,7 @@ std::string CmdProxy::Adcphase(int action) { WrongNumberOfParameters(1); } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -729,7 +729,7 @@ std::string CmdProxy::Dbitphase(int action) { auto det_type = det->getDetectorType().squash(defs::GENERIC); if (det_type == defs::EIGER || det_type == defs::MYTHEN3 || det_type == defs::GOTTHARD2) { - throw sls::RuntimeError( + throw RuntimeError( "dbitphase not implemented for this detector"); } if (action == defs::GET_ACTION) { @@ -739,7 +739,7 @@ std::string CmdProxy::Dbitphase(int action) { os << OutString(t) << '\n'; } else if (args.size() == 1) { if (args[0] != "deg") { - throw sls::RuntimeError("Unknown dbitphase argument " + + throw RuntimeError("Unknown dbitphase argument " + args[0] + ". Did you mean deg? "); } t = det->getDBITPhaseInDegrees(std::vector{det_id}); @@ -754,7 +754,7 @@ std::string CmdProxy::Dbitphase(int action) { os << args.front() << '\n'; } else if (args.size() == 2) { if (args[1] != "deg") { - throw sls::RuntimeError("Unknown dbitphase 2nd argument " + + throw RuntimeError("Unknown dbitphase 2nd argument " + args[1] + ". Did you mean deg? "); } det->setDBITPhaseInDegrees(StringTo(args[0]), @@ -764,7 +764,7 @@ std::string CmdProxy::Dbitphase(int action) { WrongNumberOfParameters(1); } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -780,7 +780,7 @@ std::string CmdProxy::ClockFrequency(int action) { } else { defs::detectorType type = det->getDetectorType().squash(defs::GENERIC); if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) { - throw sls::RuntimeError( + throw RuntimeError( "clkfreq not implemented for this detector."); } if (action == defs::GET_ACTION) { @@ -791,9 +791,9 @@ std::string CmdProxy::ClockFrequency(int action) { std::vector{det_id}); os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -811,7 +811,7 @@ std::string CmdProxy::ClockPhase(int action) { } else { defs::detectorType type = det->getDetectorType().squash(defs::GENERIC); if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) { - throw sls::RuntimeError( + throw RuntimeError( "clkphase not implemented for this detector."); } if (action == defs::GET_ACTION) { @@ -821,7 +821,7 @@ std::string CmdProxy::ClockPhase(int action) { os << OutString(t) << '\n'; } else if (args.size() == 2) { if (args[1] != "deg") { - throw sls::RuntimeError("Cannot scan argument" + args[1] + + throw RuntimeError("Cannot scan argument" + args[1] + ". Did you mean deg?"); } auto t = det->getClockPhaseinDegrees(StringTo(args[0]), @@ -838,7 +838,7 @@ std::string CmdProxy::ClockPhase(int action) { os << args[1] << '\n'; } else if (args.size() == 3) { if (args[2] != "deg") { - throw sls::RuntimeError("Cannot scan argument" + args[2] + + throw RuntimeError("Cannot scan argument" + args[2] + ". Did you mean deg?"); } det->setClockPhaseinDegrees(StringTo(args[0]), @@ -849,7 +849,7 @@ std::string CmdProxy::ClockPhase(int action) { WrongNumberOfParameters(1); } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -865,7 +865,7 @@ std::string CmdProxy::MaxClockPhaseShift(int action) { } else { defs::detectorType type = det->getDetectorType().squash(defs::GENERIC); if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) { - throw sls::RuntimeError( + throw RuntimeError( "maxclkphaseshift not implemented for this detector."); } if (action == defs::GET_ACTION) { @@ -876,9 +876,9 @@ std::string CmdProxy::MaxClockPhaseShift(int action) { std::vector{det_id}); os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("Cannot put"); + throw RuntimeError("Cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -894,7 +894,7 @@ std::string CmdProxy::ClockDivider(int action) { } else { defs::detectorType type = det->getDetectorType().squash(defs::GENERIC); if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) { - throw sls::RuntimeError( + throw RuntimeError( "clkdiv not implemented for this detector."); } if (action == defs::GET_ACTION) { @@ -912,7 +912,7 @@ std::string CmdProxy::ClockDivider(int action) { {det_id}); os << args[1] << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -949,7 +949,7 @@ std::string CmdProxy::ExternalSignal(int action) { std::vector{det_id}); os << args[0] << " " << args[1] << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -984,7 +984,7 @@ std::string CmdProxy::CurrentSource(int action) { } else if (args[1] == "nofix") { fix = false; } else { - throw sls::RuntimeError("Invalid argument: " + args[1] + + throw RuntimeError("Invalid argument: " + args[1] + ". Did you mean fix or nofix?"); } if (args.size() == 3) { @@ -997,22 +997,22 @@ std::string CmdProxy::CurrentSource(int action) { } else if (args[3] == "low") { normalCurrent = false; } else { - throw sls::RuntimeError("Invalid argument: " + args[3] + + throw RuntimeError("Invalid argument: " + args[3] + ". Did you mean normal or low?"); } det->setCurrentSource(defs::currentSrcParameters( fix, StringTo(args[2]), normalCurrent)); } else { - throw sls::RuntimeError( + throw RuntimeError( "Invalid number of parareters for this command."); } } else { - throw sls::RuntimeError( + throw RuntimeError( "Invalid number of parareters for this command."); } os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1045,9 +1045,9 @@ std::string CmdProxy::TemperatureValues(int action) { } os << "]\n"; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("Cannot put"); + throw RuntimeError("Cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1071,7 +1071,7 @@ std::string CmdProxy::Dac(int action) { // dac indices only for ctb if (args.size() > 0 && action != defs::HELP_ACTION) { if (is_int(args[0]) && type != defs::CHIPTESTBOARD) { - throw sls::RuntimeError( + throw RuntimeError( "Dac indices can only be used for chip test board. Use daclist " "to get list of dac names for current detector."); } @@ -1093,7 +1093,7 @@ std::string CmdProxy::Dac(int action) { if (args.size() == 2) { if ((args[1] != "mv") && (args[1] != "mV")) { - throw sls::RuntimeError("Unknown argument " + args[1] + + throw RuntimeError("Unknown argument " + args[1] + ". Did you mean mV?"); } mV = true; @@ -1114,7 +1114,7 @@ std::string CmdProxy::Dac(int action) { bool mV = false; if (args.size() == 3) { if ((args[2] != "mv") && (args[2] != "mV")) { - throw sls::RuntimeError("Unknown argument " + args[2] + + throw RuntimeError("Unknown argument " + args[2] + ". Did you mean mV?"); } mV = true; @@ -1125,7 +1125,7 @@ std::string CmdProxy::Dac(int action) { std::vector{det_id}); os << args[0] << ' ' << args[1] << (mV ? " mV\n" : "\n"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1145,14 +1145,14 @@ std::string CmdProxy::DacList(const int action) { WrongNumberOfParameters(0); } auto t = det->getDacNames(); - os << sls::ToString(t) << '\n'; + os << ToString(t) << '\n'; } else if (action == slsDetectorDefs::PUT_ACTION) { if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { - throw sls::RuntimeError("This detector already has fixed dac " + throw RuntimeError("This detector already has fixed dac " "names. Cannot change them."); } if (det_id != -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot configure dacnames at module level"); } if (args.size() != 18) { @@ -1161,7 +1161,7 @@ std::string CmdProxy::DacList(const int action) { det->setDacNames(args); os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1177,7 +1177,7 @@ std::string CmdProxy::DacValues(int action) { bool mv = false; if (args.size() == 1) { if ((args[0] != "mv") && (args[0] != "mV")) { - throw sls::RuntimeError("Unknown argument " + args[0] + + throw RuntimeError("Unknown argument " + args[0] + ". Did you mean mV?"); } mv = true; @@ -1199,9 +1199,9 @@ std::string CmdProxy::DacValues(int action) { } os << "]\n"; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("Cannot put"); + throw RuntimeError("Cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1217,12 +1217,12 @@ std::string CmdProxy::ResetDacs(int action) { "detector server." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { bool hardReset = false; if (args.size() == 1) { if (args[0] != "hard") { - throw sls::RuntimeError("Unknown argument " + args[0] + + throw RuntimeError("Unknown argument " + args[0] + ". Did you mean hard?"); } hardReset = true; @@ -1232,7 +1232,7 @@ std::string CmdProxy::ResetDacs(int action) { det->resetToDefaultDacs(hardReset, std::vector{det_id}); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1253,7 +1253,7 @@ std::string CmdProxy::DefaultDac(int action) { if (args.size() == 2) { auto t = det->getDefaultDac( StringTo(args[0]), - sls::StringTo(args[1]), + StringTo(args[1]), std::vector{det_id}); os << args[0] << ' ' << args[1] << ' ' << OutString(t) << '\n'; } else { @@ -1269,7 +1269,7 @@ std::string CmdProxy::DefaultDac(int action) { if (args.size() == 3) { det->setDefaultDac( StringTo(args[0]), StringTo(args[1]), - sls::StringTo(args[2]), + StringTo(args[2]), std::vector{det_id}); os << args[0] << ' ' << args[2] << ' ' << args[1] << '\n'; } else { @@ -1278,7 +1278,7 @@ std::string CmdProxy::DefaultDac(int action) { os << args[0] << ' ' << args[1] << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1297,10 +1297,10 @@ std::string CmdProxy::ReceiverStatus(int action) { auto t = det->getReceiverStatus(std::vector{det_id}); os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot put. Did you mean to use command 'rx_start' or 'rx_stop'?"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1319,10 +1319,10 @@ std::string CmdProxy::DetectorStatus(int action) { auto t = det->getDetectorStatus(std::vector{det_id}); os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot put. Did you mean to use command 'start' or 'stop'?"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1347,12 +1347,12 @@ std::string CmdProxy::Scan(int action) { os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot configure scan at module level"); + throw RuntimeError("Cannot configure scan at module level"); } // disable if (args.size() == 1) { if (StringTo(args[0]) != 0) { - throw sls::RuntimeError("Did you mean '0' to disable?"); + throw RuntimeError("Did you mean '0' to disable?"); } det->setScan(defs::scanParameters()); } @@ -1375,7 +1375,7 @@ std::string CmdProxy::Scan(int action) { } os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1392,14 +1392,14 @@ std::string CmdProxy::Trigger(int action) { "blocks till " "the frames are sent out for that trigger."; } else { - throw sls::RuntimeError("unknown command " + cmd); + throw RuntimeError("unknown command " + cmd); } os << '\n'; } else if (action == slsDetectorDefs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == slsDetectorDefs::PUT_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot execute this at module level"); + throw RuntimeError("Cannot execute this at module level"); } if (!args.empty()) { WrongNumberOfParameters(0); @@ -1411,7 +1411,7 @@ std::string CmdProxy::Trigger(int action) { det->sendSoftwareTrigger(block); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1422,7 +1422,7 @@ IpAddr CmdProxy::getIpFromAuto() { std::string rxHostname = det->getRxHostname(std::vector{det_id}).squash("none"); // Hostname could be ip try to decode otherwise look up the hostname - auto val = sls::IpAddr{rxHostname}; + auto val = IpAddr{rxHostname}; if (val == 0) { val = HostnameToIp(rxHostname.c_str()); } @@ -1485,10 +1485,10 @@ std::string CmdProxy::UDPDestinationList(int action) { WrongNumberOfParameters(0); } if (det_id == -1) { - throw sls::RuntimeError("udp_dstlist must be at module level."); + throw RuntimeError("udp_dstlist must be at module level."); } if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) { - throw sls::RuntimeError(std::string("Invalid receiver index ") + + throw RuntimeError(std::string("Invalid receiver index ") + std::to_string(rx_id) + std::string(" to set round robin entry.")); } @@ -1499,17 +1499,17 @@ std::string CmdProxy::UDPDestinationList(int action) { WrongNumberOfParameters(1); } if (det_id == -1) { - throw sls::RuntimeError("udp_dstlist must be at module level."); + throw RuntimeError("udp_dstlist must be at module level."); } if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) { - throw sls::RuntimeError( + throw RuntimeError( "Invalid receiver index to set round robin entry."); } auto t = getUdpEntry(); det->setDestinationUDPList(t, det_id); os << ToString(args) << std::endl; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1544,7 +1544,7 @@ std::string CmdProxy::UDPDestinationIP(int action) { os << args.front() << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1580,7 +1580,7 @@ std::string CmdProxy::UDPDestinationIP2(int action) { os << args.front() << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1614,11 +1614,11 @@ std::string CmdProxy::ReceiverHostname(int action) { if (args.size() > 1) { // multiple in mulitple if (args[0].find('+') != std::string::npos) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot add multiple receivers at module level"); } if (det_id != -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot add multiple receivers at module level"); } det->setRxHostname(args); @@ -1629,10 +1629,10 @@ std::string CmdProxy::ReceiverHostname(int action) { // multiple receivers concatenated with + if (args[0].find('+') != std::string::npos) { if (det_id != -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot add multiple receivers at module level"); } - auto t = sls::split(args[0], '+'); + auto t = split(args[0], '+'); det->setRxHostname(t); os << ToString(t) << '\n'; } @@ -1643,7 +1643,7 @@ std::string CmdProxy::ReceiverHostname(int action) { } } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1687,7 +1687,7 @@ std::string CmdProxy::Rx_ROI(int action) { det->setRxROI(t); os << t << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1722,7 +1722,7 @@ std::string CmdProxy::ZMQHWM(int action) { det->setClientZmqHwm(t); os << det->getClientZmqHwm() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1758,7 +1758,7 @@ std::string CmdProxy::RateCorrection(int action) { os << args.front() << "ns\n"; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1771,7 +1771,7 @@ std::string CmdProxy::PulsePixel(int action) { "coordinates (x, y). Advanced User!" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("cannot get"); + throw RuntimeError("cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 3) { WrongNumberOfParameters(3); @@ -1781,9 +1781,9 @@ std::string CmdProxy::PulsePixel(int action) { c.x = StringTo(args[1]); c.y = StringTo(args[2]); det->pulsePixel(n, c, std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1796,7 +1796,7 @@ std::string CmdProxy::PulsePixelAndMove(int action) { "moves relatively by (x, y). Advanced User!" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("cannot get"); + throw RuntimeError("cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 3) { WrongNumberOfParameters(3); @@ -1806,9 +1806,9 @@ std::string CmdProxy::PulsePixelAndMove(int action) { c.x = StringTo(args[1]); c.y = StringTo(args[2]); det->pulsePixelNMove(n, c, std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1822,7 +1822,7 @@ std::string CmdProxy::PulseChip(int action) { "where partialreset = 0). Advanced User!" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("cannot get"); + throw RuntimeError("cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 1) { WrongNumberOfParameters(1); @@ -1830,7 +1830,7 @@ std::string CmdProxy::PulseChip(int action) { det->pulseChip(StringTo(args[0]), std::vector{det_id}); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1850,7 +1850,7 @@ std::string CmdProxy::Quad(int action) { os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot execute quad at module level"); + throw RuntimeError("Cannot execute quad at module level"); } if (args.size() != 1) { WrongNumberOfParameters(1); @@ -1858,7 +1858,7 @@ std::string CmdProxy::Quad(int action) { det->setQuad(StringTo(args[0])); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1888,7 +1888,7 @@ std::string CmdProxy::DataStream(int action) { StringTo(args[1]), std::vector{det_id}); os << args << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1917,13 +1917,13 @@ std::string CmdProxy::TemperatureEvent(int action) { WrongNumberOfParameters(1); } if (StringTo(args[0]) != 0) { - throw sls::RuntimeError("Unknown argument for temp event. Did you " + throw RuntimeError("Unknown argument for temp event. Did you " "mean 0 to reset event?"); } det->resetTemperatureEvent(std::vector{det_id}); os << "cleared" << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1947,7 +1947,7 @@ std::string CmdProxy::ROI(int action) { os << t << '\n'; } else if (action == defs::PUT_ACTION) { if (det_id == -1 && det->size() > 1) { - throw sls::RuntimeError("Cannot execute ROI at multi module level"); + throw RuntimeError("Cannot execute ROI at multi module level"); } if (args.size() != 2) { WrongNumberOfParameters(2); @@ -1956,7 +1956,7 @@ std::string CmdProxy::ROI(int action) { det->setROI(t, det_id); os << t << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -1984,9 +1984,9 @@ std::string CmdProxy::InjectChannel(int action) { } det->setInjectChannel(StringTo(args[0]), StringTo(args[1]), {det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2015,9 +2015,9 @@ std::string CmdProxy::VetoPhoton(int action) { det->setVetoPhoton(StringTo(args[0]), StringTo(args[1]), StringTo(args[2]), args[3], std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2030,16 +2030,16 @@ std::string CmdProxy::VetoReference(int action) { "reference for all 128 channels for all chips." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("cannot get vetoref. Did you mean vetophoton?"); + throw RuntimeError("cannot get vetoref. Did you mean vetophoton?"); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { WrongNumberOfParameters(2); } det->setVetoReference(StringTo(args[0]), StringTo(args[1]), {det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2053,7 +2053,7 @@ std::string CmdProxy::VetoFile(int action) { "file should have 128 rows of gain index and 12 bit value in dec" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError( + throw RuntimeError( "cannot get vetofile. Did you mean vetophoton?"); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { @@ -2061,9 +2061,9 @@ std::string CmdProxy::VetoFile(int action) { } det->setVetoFile(StringTo(args[0]), args[1], std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2103,15 +2103,15 @@ std::string CmdProxy::BurstMode(int action) { t = defs::CONTINUOUS_EXTERNAL; break; default: - throw sls::RuntimeError("Unknown burst mode " + args[0]); + throw RuntimeError("Unknown burst mode " + args[0]); } } catch (...) { - t = sls::StringTo(args[0]); + t = StringTo(args[0]); } det->setBurstMode(t, std::vector{det_id}); - os << sls::ToString(t) << '\n'; // no args to convert 0,1,2 as well + os << ToString(t) << '\n'; // no args to convert 0,1,2 as well } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -2144,7 +2144,7 @@ std::string CmdProxy::VetoStreaming(int action) { for (const auto &arg : args) { if (arg == "none") { if (args.size() > 1) { - throw sls::RuntimeError( + throw RuntimeError( std::string( "cannot have other arguments with 'none'. args: ") + ToString(args)); @@ -2156,7 +2156,7 @@ std::string CmdProxy::VetoStreaming(int action) { det->setVetoStream(interface, std::vector{det_id}); os << ToString(interface) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2175,7 +2175,7 @@ std::string CmdProxy::VetoAlgorithm(int action) { defs::streamingInterface interface = StringTo(args[0]); if (interface == defs::streamingInterface::NONE) { - throw sls::RuntimeError( + throw RuntimeError( "Must specify an interface to set algorithm"); } auto t = det->getVetoAlgorithm(interface, std::vector{det_id}); @@ -2188,13 +2188,13 @@ std::string CmdProxy::VetoAlgorithm(int action) { defs::streamingInterface interface = StringTo(args[1]); if (interface == defs::streamingInterface::NONE) { - throw sls::RuntimeError( + throw RuntimeError( "Must specify an interface to set algorithm"); } det->setVetoAlgorithm(alg, interface, std::vector{det_id}); os << ToString(alg) << ' ' << ToString(interface) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2226,7 +2226,7 @@ std::string CmdProxy::ConfigureADC(int action) { os << '[' << args[0] << ", " << args[1] << ", " << ToStringHex(value) << "]\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2251,7 +2251,7 @@ std::string CmdProxy::BadChannels(int action) { det->setBadChannels(args[0], std::vector{det_id}); os << "successfully loaded" << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2272,7 +2272,7 @@ std::string CmdProxy::Counters(int action) { WrongNumberOfParameters(0); } auto mask = det->getCounterMask(std::vector{det_id}).squash(-1); - os << sls::ToString(getSetBits(mask)) << '\n'; + os << ToString(getSetBits(mask)) << '\n'; } else if (action == defs::PUT_ACTION) { if (args.empty()) { WrongNumberOfParameters(1); @@ -2285,14 +2285,14 @@ std::string CmdProxy::Counters(int action) { if (mask & (1 << val)) { std::ostringstream oss; oss << "Duplicate counter values (" << val << ") in arguments"; - throw sls::RuntimeError(oss.str()); + throw RuntimeError(oss.str()); } mask |= (1 << val); } det->setCounterMask(mask, std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2308,7 +2308,7 @@ std::string CmdProxy::GateDelay(int action) { } else if (cmd == "gatedelay3") { gateIndex = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } @@ -2374,7 +2374,7 @@ std::string CmdProxy::GateDelay(int action) { os << args[0] << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2391,7 +2391,7 @@ std::string CmdProxy::GainCaps(int action) { WrongNumberOfParameters(0); auto tmp = det->getGainCaps(); - sls::Result csr; + Result csr; for (auto val : tmp) { if (val) csr.push_back(static_cast(val)); @@ -2405,13 +2405,13 @@ std::string CmdProxy::GainCaps(int action) { int caps = 0; for (const auto &arg : args) { if (arg != "0") - caps |= sls::StringTo(arg); + caps |= StringTo(arg); } det->setGainCaps(caps); os << OutString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2436,7 +2436,7 @@ std::string CmdProxy::Samples(int action) { int as = a.squash(-1); int ds = d.squash(-1); if (as == -1 || ds == -1 || as != ds) { // check if a == d? - throw sls::RuntimeError( + throw RuntimeError( "Different samples. Use asamples or dsamples."); } } @@ -2454,7 +2454,7 @@ std::string CmdProxy::Samples(int action) { } os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2474,7 +2474,7 @@ std::string CmdProxy::SlowAdc(int action) { } int nchan = StringTo(args[0]); if (nchan < 0 || nchan > 7) { - throw sls::RuntimeError("Unknown adc argument " + args[0]); + throw RuntimeError("Unknown adc argument " + args[0]); } auto t = det->getSlowADC( static_cast(nchan + defs::SLOW_ADC0), @@ -2486,9 +2486,9 @@ std::string CmdProxy::SlowAdc(int action) { os << OutString(result) << " mV\n"; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("cannot put"); + throw RuntimeError("cannot put"); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2526,9 +2526,9 @@ std::string CmdProxy::ReceiverDbitList(int action) { } } det->setRxDbitList(t, std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2542,7 +2542,7 @@ std::string CmdProxy::DigitalIODelay(int action) { "Resolution is 25 ps." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { WrongNumberOfParameters(2); @@ -2550,9 +2550,9 @@ std::string CmdProxy::DigitalIODelay(int action) { det->setDigitalIODelay(StringTo(args[0]), StringTo(args[1]), std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2567,7 +2567,7 @@ std::string CmdProxy::Pattern(int action) { "directly to server (instead of executing line by line)" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 1) { WrongNumberOfParameters(1); @@ -2575,7 +2575,7 @@ std::string CmdProxy::Pattern(int action) { det->setPattern(args[0], std::vector{det_id}); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2606,7 +2606,7 @@ std::string CmdProxy::PatternWord(int action) { os << '[' << ToStringHex(addr, 4) << ", " << ToStringHex(word, 16) << "]\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2632,7 +2632,7 @@ std::string CmdProxy::PatternLoopAddresses(int action) { "of loop 2." << '\n'; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } } else { @@ -2646,7 +2646,7 @@ std::string CmdProxy::PatternLoopAddresses(int action) { } else if (cmd == "patloop2") { level = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } if (action == defs::GET_ACTION) { @@ -2667,7 +2667,7 @@ std::string CmdProxy::PatternLoopAddresses(int action) { os << '[' << ToStringHex(start, 4) << ", " << ToStringHex(stop, 4) << "]\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -2690,7 +2690,7 @@ std::string CmdProxy::PatternLoopCycles(int action) { "loop 2." << '\n'; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } } else { @@ -2702,7 +2702,7 @@ std::string CmdProxy::PatternLoopCycles(int action) { } else if (cmd == "patnloop2") { level = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } if (action == defs::GET_ACTION) { @@ -2719,7 +2719,7 @@ std::string CmdProxy::PatternLoopCycles(int action) { std::vector{det_id}); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -2736,7 +2736,7 @@ std::string CmdProxy::PatternWaitAddress(int action) { } else if (cmd == "patwait2") { os << "[addr] \n\t[Ctb][Moench][Mythen3] Wait 2 address." << '\n'; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } } else { @@ -2748,7 +2748,7 @@ std::string CmdProxy::PatternWaitAddress(int action) { } else if (cmd == "patwait2") { level = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } if (action == defs::GET_ACTION) { @@ -2765,7 +2765,7 @@ std::string CmdProxy::PatternWaitAddress(int action) { det->setPatternWaitAddr(level, addr, std::vector{det_id}); os << ToStringHex(addr, 4) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -2788,7 +2788,7 @@ std::string CmdProxy::PatternWaitTime(int action) { "cycles." << '\n'; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } } else { @@ -2800,7 +2800,7 @@ std::string CmdProxy::PatternWaitTime(int action) { } else if (cmd == "patwaittime2") { level = 2; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } if (action == defs::GET_ACTION) { @@ -2817,7 +2817,7 @@ std::string CmdProxy::PatternWaitTime(int action) { {det_id}); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -2853,9 +2853,9 @@ std::string CmdProxy::AdditionalJsonHeader(int action) { } } det->setAdditionalJsonHeader(json, std::vector{det_id}); - os << sls::ToString(json) << '\n'; + os << ToString(json) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2895,7 +2895,7 @@ std::string CmdProxy::JsonParameter(int action) { os << "{" << args[0] << ": " << args[1] << "}" << '\n'; } } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2916,12 +2916,12 @@ std::string CmdProxy::ProgramFpga(int action) { "(full path). Then, detector controller is rebooted." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { bool forceDeteleNormalFile = false; if (args.size() == 2) { if (args[1] != "--force-delete-normal-file") { - throw sls::RuntimeError( + throw RuntimeError( "Could not scan second argument. Did you " "mean --force-delete-normal-file?"); } @@ -2933,7 +2933,7 @@ std::string CmdProxy::ProgramFpga(int action) { std::vector{det_id}); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2951,7 +2951,7 @@ std::string CmdProxy::UpdateDetectorServer(int action) { "to the link, which is effective after a reboot." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 1) { WrongNumberOfParameters(1); @@ -2959,7 +2959,7 @@ std::string CmdProxy::UpdateDetectorServer(int action) { det->updateDetectorServer(args[0], std::vector{det_id}); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -2975,7 +2975,7 @@ std::string CmdProxy::UpdateKernel(int action) { "reboots with new kernel." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 1) { WrongNumberOfParameters(1); @@ -2983,7 +2983,7 @@ std::string CmdProxy::UpdateKernel(int action) { det->updateKernel(args[0], std::vector{det_id}); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3003,7 +3003,7 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) { "path of programming file" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { WrongNumberOfParameters(2); @@ -3011,13 +3011,13 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) { int fpos = args.size() - 1; if (args[fpos].find(".pof") == std::string::npos && args[fpos].find(".rbf") == std::string::npos) { - throw sls::RuntimeError("Programming file must be a pof/rbf file."); + throw RuntimeError("Programming file must be a pof/rbf file."); } det->updateFirmwareAndServer(args[0], args[1], std::vector{det_id}); os << "successful\n"; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3045,9 +3045,9 @@ std::string CmdProxy::Register(int action) { det->writeRegister(StringTo(args[0]), StringTo(args[1]), std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3060,7 +3060,7 @@ std::string CmdProxy::AdcRegister(int action) { "to an adc register in hex. Advanced user Function!" << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get."); + throw RuntimeError("Cannot get."); } else if (action == defs::PUT_ACTION) { if (args.size() != 2) { WrongNumberOfParameters(2); @@ -3068,9 +3068,9 @@ std::string CmdProxy::AdcRegister(int action) { det->writeAdcRegister(StringTo(args[0]), StringTo(args[1]), std::vector{det_id}); - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3089,12 +3089,12 @@ std::string CmdProxy::BitOperations(int action) { os << "[reg address in hex] [bit index]\n\tGets bit in address." << '\n'; } else { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } } else { if (cmd != "setbit" && cmd != "clearbit" && cmd != "getbit") { - throw sls::RuntimeError( + throw RuntimeError( "Unknown command, use list to list all commands"); } if (args.size() != 2) { @@ -3108,22 +3108,22 @@ std::string CmdProxy::BitOperations(int action) { } if (action == defs::GET_ACTION) { if (cmd == "setbit" || cmd == "clearbit") { - throw sls::RuntimeError("Cannot get"); + throw RuntimeError("Cannot get"); } auto t = det->getBit(addr, bitnr, std::vector{det_id}); os << OutString(t) << '\n'; } else if (action == defs::PUT_ACTION) { if (cmd == "getbit") { - throw sls::RuntimeError("Cannot put"); + throw RuntimeError("Cannot put"); } if (cmd == "setbit") { det->setBit(addr, bitnr, std::vector{det_id}); } else if (cmd == "clearbit") { det->clearBit(addr, bitnr, std::vector{det_id}); } - os << sls::ToString(args) << '\n'; + os << ToString(args) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } } return os.str(); @@ -3141,7 +3141,7 @@ std::string CmdProxy::InitialChecks(int action) { << '\n'; } else if (action == defs::GET_ACTION) { if (det_id != -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot enable/disable initial checks at module level"); } if (!args.empty()) { @@ -3151,7 +3151,7 @@ std::string CmdProxy::InitialChecks(int action) { os << t << '\n'; } else if (action == defs::PUT_ACTION) { if (det_id != -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot get initial checks enable at module level"); } if (args.size() != 1) { @@ -3160,7 +3160,7 @@ std::string CmdProxy::InitialChecks(int action) { det->setInitialChecks(StringTo(args[0])); os << args.front() << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3174,7 +3174,7 @@ std::string CmdProxy::ExecuteCommand(int action) { os << "[command]\n\tExecutes command on detector server console." << '\n'; } else if (action == defs::GET_ACTION) { - throw sls::RuntimeError("Cannot get."); + throw RuntimeError("Cannot get."); } else if (action == defs::PUT_ACTION) { std::string command; for (auto &i : args) { @@ -3183,7 +3183,7 @@ std::string CmdProxy::ExecuteCommand(int action) { auto t = det->executeCommand(command, std::vector{det_id}); os << OutString(t) << '\n'; } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } @@ -3197,7 +3197,7 @@ std::string CmdProxy::UserDetails(int action) { << '\n'; } else if (action == defs::GET_ACTION) { if (det_id != -1) { - throw sls::RuntimeError("Cannot execute this at module level"); + throw RuntimeError("Cannot execute this at module level"); } if (!args.empty()) { WrongNumberOfParameters(0); @@ -3205,9 +3205,9 @@ std::string CmdProxy::UserDetails(int action) { auto t = det->getUserDetails(); os << t << '\n'; } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("Cannot put."); + throw RuntimeError("Cannot put."); } else { - throw sls::RuntimeError("Unknown action"); + throw RuntimeError("Unknown action"); } return os.str(); } diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 76b69d8e7..1f83ca131 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -11,6 +11,8 @@ #include #include +namespace sls { + /** Macro to make an integer command. * CMDNAME name of the function that does the command * GETFCN Detector function to get @@ -53,7 +55,7 @@ os << args[0] << '\n'; \ } \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -75,9 +77,9 @@ WrongNumberOfParameters(1); \ } \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ - throw sls::RuntimeError("cannot put"); \ + throw RuntimeError("cannot put"); \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -102,7 +104,7 @@ det->SETFCN(args[0], std::vector{det_id}); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -128,7 +130,7 @@ det->SETFCN(val, std::vector{det_id}); \ os << ToStringHex(val, 16) << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -154,7 +156,7 @@ det->SETFCN(val, std::vector{det_id}); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -180,7 +182,7 @@ det->SETFCN(val, std::vector{det_id}); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -206,7 +208,7 @@ det->SETFCN(val, det_id); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -232,7 +234,7 @@ det->SETFCN(val, det_id); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -252,7 +254,7 @@ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (det_id != -1) { \ - throw sls::RuntimeError( \ + throw RuntimeError( \ "Cannot execute this at module level"); \ } \ if (args.size() != 1) { \ @@ -262,7 +264,7 @@ det->SETFCN(val); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -273,7 +275,7 @@ std::ostringstream os; \ os << cmd << ' '; \ if (det_id != -1) { \ - throw sls::RuntimeError("Cannot execute this at module level"); \ + throw RuntimeError("Cannot execute this at module level"); \ } \ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ @@ -291,7 +293,7 @@ det->SETFCN(val); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -317,7 +319,7 @@ det->SETFCN(INDEX, val, std::vector{det_id}); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -345,7 +347,7 @@ std::vector{det_id}); \ os << args[0] << ' ' << args[1] << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -356,12 +358,12 @@ std::ostringstream os; \ os << cmd << ' '; \ if (det_id != -1) { \ - throw sls::RuntimeError("Cannot execute this at module level"); \ + throw RuntimeError("Cannot execute this at module level"); \ } \ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - throw sls::RuntimeError("Cannot get"); \ + throw RuntimeError("Cannot get"); \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (!args.empty()) { \ WrongNumberOfParameters(0); \ @@ -369,7 +371,7 @@ det->SETFCN(); \ os << "successful\n"; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -382,7 +384,7 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - throw sls::RuntimeError("Cannot get"); \ + throw RuntimeError("Cannot get"); \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (!args.empty()) { \ WrongNumberOfParameters(0); \ @@ -390,7 +392,7 @@ det->SETFCN(std::vector{det_id}); \ os << "successful\n"; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -401,12 +403,12 @@ std::ostringstream os; \ os << cmd << ' '; \ if (det_id != -1) { \ - throw sls::RuntimeError("Cannot execute this at module level"); \ + throw RuntimeError("Cannot execute this at module level"); \ } \ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - throw sls::RuntimeError("Cannot get"); \ + throw RuntimeError("Cannot get"); \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ WrongNumberOfParameters(1); \ @@ -414,7 +416,7 @@ det->SETFCN(args[0]); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -427,7 +429,7 @@ if (action == slsDetectorDefs::HELP_ACTION) \ os << HLPSTR << '\n'; \ else if (action == slsDetectorDefs::GET_ACTION) { \ - throw sls::RuntimeError("Cannot get"); \ + throw RuntimeError("Cannot get"); \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ if (args.size() != 1) { \ WrongNumberOfParameters(1); \ @@ -435,7 +437,7 @@ det->SETFCN(args[0], std::vector{det_id}); \ os << args.front() << '\n'; \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -454,9 +456,9 @@ auto t = det->GETFCN(std::vector{det_id}); \ os << OutString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ - throw sls::RuntimeError("Cannot put"); \ + throw RuntimeError("Cannot put"); \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -473,11 +475,11 @@ WrongNumberOfParameters(0); \ } \ auto t = det->GETFCN(); \ - os << sls::ToString(t) << '\n'; \ + os << ToString(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ - throw sls::RuntimeError("Cannot put"); \ + throw RuntimeError("Cannot put"); \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -496,9 +498,9 @@ auto t = det->GETFCN(std::vector{det_id}); \ os << OutStringHex(t) << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ - throw sls::RuntimeError("Cannot put"); \ + throw RuntimeError("Cannot put"); \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } @@ -516,15 +518,13 @@ auto t = det->GETFCN(VAL, std::vector{det_id}); \ os << OutString(t) << APPEND << '\n'; \ } else if (action == slsDetectorDefs::PUT_ACTION) { \ - throw sls::RuntimeError("Cannot put"); \ + throw RuntimeError("Cannot put"); \ } else { \ - throw sls::RuntimeError("Unknown action"); \ + throw RuntimeError("Unknown action"); \ } \ return os.str(); \ } -namespace sls { - class CmdProxy { public: explicit CmdProxy(Detector *ptr) : det(ptr) {} @@ -558,7 +558,7 @@ class CmdProxy { return ToStringHex(value, width); } - template std::string OutString(const sls::Result &value) { + template std::string OutString(const Result &value) { if (value.equal()) return ToString(value.front()); return ToString(value); @@ -1251,7 +1251,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( settings, getSettings, setSettings, - sls::StringTo, + StringTo, "[standard, fast, highgain, dynamicgain, lowgain, " "mediumgain, veryhighgain, highgain0, " "fixgain1, fixgain2, forceswitchg1, forceswitchg2, " @@ -1354,7 +1354,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( timing, getTimingMode, setTimingMode, - sls::StringTo, + StringTo, "[auto|trigger|gating|burst_trigger]\n\tTiming Mode of " "detector.\n\t[Jungfrau][Gotthard][Ctb][Moench][Gotthard2] " "[auto|trigger]\n\t[Mythen3] " @@ -1726,7 +1726,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( rx_discardpolicy, getRxFrameDiscardPolicy, setRxFrameDiscardPolicy, - sls::StringTo, + StringTo, "[nodiscard (default)|discardempty|discardpartial(fastest)]\n\tFrame " "discard policy of receiver. nodiscard does not discard frames, " "discardempty discards empty frames, discardpartial discards partial " @@ -1776,7 +1776,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( fformat, getFileFormat, setFileFormat, - sls::StringTo, + StringTo, "[binary|hdf5]\n\tFile format of data file. For HDF5, package must be " "compiled with HDF5 flags. Default is binary."); @@ -1992,13 +1992,13 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( gainmode, getGainMode, setGainMode, - sls::StringTo, + StringTo, "[dynamicgain|forceswitchg1|forceswitchg2|fixg1|fixg2|fixg0]\n\t[" "Jungfrau] Gain mode.\n\tCAUTION: Do not use fixg0 without caution, " "you can damage the detector!!!"); INTEGER_COMMAND_VEC_ID(filtercells, getNumberOfFilterCells, - setNumberOfFilterCells, sls::StringTo, + setNumberOfFilterCells, StringTo, "[0-12]\n\t[Jungfrau] Set Filter Cell. Only for " "chipv1.1. Advanced user Command"); @@ -2034,7 +2034,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( timingsource, getTimingSource, setTimingSource, - sls::StringTo, + StringTo, "[internal|external]\n\t[Gotthard2] Timing source. Internal is crystal " "and external is system timing. Default is internal."); @@ -2121,7 +2121,7 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( romode, getReadoutMode, setReadoutMode, - sls::StringTo, + StringTo, "[analog|digital|analog_digital]\n\t[CTB] Readout mode. " "Default is analog."); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 7b076511e..19db54e9a 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -56,7 +56,7 @@ void freeSharedMemory(int detectorIndex, int moduleIndex) { using defs = slsDetectorDefs; Detector::Detector(int shm_id) - : pimpl(sls::make_unique(shm_id)) {} + : pimpl(make_unique(shm_id)) {} Detector::~Detector() = default; @@ -66,7 +66,7 @@ void Detector::freeSharedMemory() { pimpl->freeSharedMemory(); } void Detector::loadConfig(const std::string &fname) { int shm_id = getShmId(); freeSharedMemory(); - pimpl = sls::make_unique(shm_id); + pimpl = make_unique(shm_id); LOG(logINFO) << "Loading configuration file: " << fname; loadParameters(fname); } @@ -871,7 +871,7 @@ Result Detector::getNumberofUDPInterfaces(Positions pos) const { void Detector::setNumberofUDPInterfaces(int n, Positions pos) { if (getDetectorType().squash() != defs::JUNGFRAU) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot set number of udp interfaces for this detector."); } // also called by vetostream (for gotthard2) @@ -951,7 +951,7 @@ Result Detector::getDestinationUDPList(const uint32_t entry, void Detector::setDestinationUDPList(const UdpDestination dest, const int module_id) { if (module_id == -1 && size() > 1) { - throw sls::RuntimeError("Cannot set this parameter at detector level."); + throw RuntimeError("Cannot set this parameter at detector level."); } pimpl->Parallel(&Module::setDestinationUDPList, {module_id}, dest); } @@ -1194,7 +1194,7 @@ void Detector::setRxLock(bool value, Positions pos) { pimpl->Parallel(&Module::setReceiverLock, pos, value); } -Result Detector::getRxLastClientIP(Positions pos) const { +Result Detector::getRxLastClientIP(Positions pos) const { return pimpl->Parallel(&Module::getReceiverLastClientIP, pos); } @@ -2278,7 +2278,7 @@ void Detector::resetFPGA(Positions pos) { void Detector::updateDetectorServer(const std::string &fname, Positions pos) { LOG(logINFO) << "Updating Detector Server (no tftp)..."; std::vector buffer = readBinaryFile(fname, "Update Detector Server"); - std::string filename = sls::getFileNameFromFilePath(fname); + std::string filename = getFileNameFromFilePath(fname); pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename); if (getDetectorType().squash() != defs::EIGER) { rebootController(pos); @@ -2287,7 +2287,7 @@ void Detector::updateDetectorServer(const std::string &fname, Positions pos) { void Detector::updateKernel(const std::string &fname, Positions pos) { LOG(logINFO) << "Updating Kernel..."; - std::vector buffer = sls::readBinaryFile(fname, "Update Kernel"); + std::vector buffer = readBinaryFile(fname, "Update Kernel"); pimpl->Parallel(&Module::updateKernel, pos, buffer); rebootController(pos); } @@ -2302,7 +2302,7 @@ void Detector::updateFirmwareAndServer(const std::string &sname, LOG(logINFO) << "Updating Firmware and Detector Server (no tftp)..."; LOG(logINFO) << "Updating Detector Server (no tftp)..."; std::vector buffer = readBinaryFile(sname, "Update Detector Server"); - std::string filename = sls::getFileNameFromFilePath(sname); + std::string filename = getFileNameFromFilePath(sname); pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename); programFPGA(fname, false, pos); } @@ -2390,7 +2390,7 @@ void Detector::setDetectorLock(bool lock, Positions pos) { pimpl->Parallel(&Module::setLockDetector, pos, lock); } -Result Detector::getLastClientIP(Positions pos) const { +Result Detector::getLastClientIP(Positions pos) const { return pimpl->Parallel(&Module::getLastClientIP, pos); } diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 9853cb834..aedafcd35 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -186,7 +186,7 @@ void DetectorImpl::initializeMembers(bool verify) { for (int i = 0; i < shm()->totalNumberOfModules; i++) { try { modules.push_back( - sls::make_unique(detectorIndex, i, verify)); + make_unique(detectorIndex, i, verify)); } catch (...) { modules.clear(); throw; @@ -199,11 +199,11 @@ void DetectorImpl::updateUserdetails() { memset(shm()->lastUser, 0, sizeof(shm()->lastUser)); memset(shm()->lastDate, 0, sizeof(shm()->lastDate)); try { - sls::strcpy_safe(shm()->lastUser, exec("whoami").c_str()); - sls::strcpy_safe(shm()->lastDate, exec("date").c_str()); + strcpy_safe(shm()->lastUser, exec("whoami").c_str()); + strcpy_safe(shm()->lastDate, exec("date").c_str()); } catch (...) { - sls::strcpy_safe(shm()->lastUser, "errorreading"); - sls::strcpy_safe(shm()->lastDate, "errorreading"); + strcpy_safe(shm()->lastUser, "errorreading"); + strcpy_safe(shm()->lastDate, "errorreading"); } } @@ -279,7 +279,7 @@ void DetectorImpl::addModule(const std::string &hostname) { int port = DEFAULT_PORTNO; std::string host = hostname; - auto res = sls::split(hostname, ':'); + auto res = split(hostname, ':'); if (res.size() > 1) { host = res[0]; port = StringTo(res[1]); @@ -303,12 +303,12 @@ void DetectorImpl::addModule(const std::string &hostname) { // gotthard cannot have more than 2 modules (50um=1, 25um=2 if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) { freeSharedMemory(); - throw sls::RuntimeError("Gotthard cannot have more than 2 modules"); + throw RuntimeError("Gotthard cannot have more than 2 modules"); } auto pos = modules.size(); modules.emplace_back( - sls::make_unique(type, detectorIndex, pos, false)); + make_unique(type, detectorIndex, pos, false)); shm()->totalNumberOfModules = modules.size(); modules[pos]->setControlPort(port); modules[pos]->setStopPort(port + 1); @@ -334,7 +334,7 @@ void DetectorImpl::updateDetectorSize() { const slsDetectorDefs::xy modSize = modules[0]->getNumberOfChannels(); if (modSize.x == 0 || modSize.y == 0) { - throw sls::RuntimeError( + throw RuntimeError( "Module size for x or y dimensions is 0. Unable to proceed in " "updating detector size. "); } @@ -458,7 +458,7 @@ int DetectorImpl::createReceivingDataSockets() { portnum += (iSocket % numUDPInterfaces); try { zmqSocket.push_back( - sls::make_unique(modules[iSocket / numUDPInterfaces] + make_unique(modules[iSocket / numUDPInterfaces] ->getClientStreamingIP() .str() .c_str(), @@ -468,7 +468,7 @@ int DetectorImpl::createReceivingDataSockets() { if (hwm >= 0) { zmqSocket[iSocket]->SetReceiveHighWaterMark(hwm); if (zmqSocket[iSocket]->GetReceiveHighWaterMark() != hwm) { - throw sls::ZmqSocketError("Could not set zmq rcv hwm to " + + throw ZmqSocketError("Could not set zmq rcv hwm to " + std::to_string(hwm)); } } @@ -566,8 +566,8 @@ void DetectorImpl::readFrameFromReceiver() { // allocate size = zHeader.imageSize; multisize = size * zmqSocket.size(); - image = sls::make_unique(size); - multiframe = sls::make_unique(multisize); + image = make_unique(size); + multiframe = make_unique(multisize); memset(multiframe.get(), 0xFF, multisize); // dynamic range dynamicRange = zHeader.dynamicRange; @@ -1037,7 +1037,7 @@ int DetectorImpl::getClientStreamingHwm() const { return shm()->zmqHwm; } // enabled - sls::Result result; + Result result; result.reserve(zmqSocket.size()); for (auto &it : zmqSocket) { result.push_back(it->GetReceiveHighWaterMark()); @@ -1048,7 +1048,7 @@ int DetectorImpl::getClientStreamingHwm() const { void DetectorImpl::setClientStreamingHwm(const int limit) { if (limit < -1) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot set hwm to less than -1 (-1 is lib default)."); } // update shm @@ -1062,7 +1062,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) { it->SetReceiveHighWaterMark(limit); if (it->GetReceiveHighWaterMark() != limit) { shm()->zmqHwm = -1; - throw sls::ZmqSocketError("Could not set zmq rcv hwm to " + + throw ZmqSocketError("Could not set zmq rcv hwm to " + std::to_string(limit)); } } @@ -1336,7 +1336,7 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { } // get srcSize to print progress - ssize_t srcSize = sls::getFileSize(src, "Program FPGA"); + ssize_t srcSize = getFileSize(src, "Program FPGA"); // create temp destination file char destfname[] = "/tmp/SLS_DET_MCB.XXXXXX"; @@ -1417,7 +1417,7 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { return buffer; } -sls::Result DetectorImpl::getDefaultDac(defs::dacIndex index, +Result DetectorImpl::getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, Positions pos) { return Parallel(&Module::getDefaultDac, pos, index, sett); diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index d0115391c..2c2845072 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -6,10 +6,7 @@ #include "sls/Result.h" #include "sls/logger.h" #include "sls/sls_detector_defs.h" - #include "CtbConfig.h" -class ZmqSocket; -class detectorData; #include #include @@ -17,18 +14,19 @@ class detectorData; #include #include #include - -#define DETECTOR_SHMAPIVERSION 0x190809 -#define DETECTOR_SHMVERSION 0x220505 -#define SHORT_STRING_LENGTH 50 - #include #include namespace sls { +class ZmqSocket; +class detectorData; class Module; +#define DETECTOR_SHMAPIVERSION 0x190809 +#define DETECTOR_SHMVERSION 0x220505 +#define SHORT_STRING_LENGTH 50 + /** * @short structure allocated in shared memory to store detector settings * for IPC and cache @@ -88,12 +86,12 @@ class DetectorImpl : public virtual slsDetectorDefs { template struct NonDeduced { using type = CT; }; template - sls::Result Parallel(RT (sls::Module::*somefunc)(CT...), + Result Parallel(RT (Module::*somefunc)(CT...), std::vector positions, typename NonDeduced::type... Args) { if (modules.empty()) - throw sls::RuntimeError("No modules added"); + throw RuntimeError("No modules added"); if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { positions.resize(modules.size()); @@ -103,11 +101,11 @@ class DetectorImpl : public virtual slsDetectorDefs { futures.reserve(positions.size()); for (size_t i : positions) { if (i >= modules.size()) - throw sls::RuntimeError("Module out of range"); + throw RuntimeError("Module out of range"); futures.push_back(std::async(std::launch::async, somefunc, modules[i].get(), Args...)); } - sls::Result result; + Result result; result.reserve(positions.size()); for (auto &i : futures) { result.push_back(i.get()); @@ -116,12 +114,12 @@ class DetectorImpl : public virtual slsDetectorDefs { } template - sls::Result Parallel(RT (sls::Module::*somefunc)(CT...) const, + Result Parallel(RT (Module::*somefunc)(CT...) const, std::vector positions, typename NonDeduced::type... Args) const { if (modules.empty()) - throw sls::RuntimeError("No modules added"); + throw RuntimeError("No modules added"); if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { positions.resize(modules.size()); @@ -131,11 +129,11 @@ class DetectorImpl : public virtual slsDetectorDefs { futures.reserve(positions.size()); for (size_t i : positions) { if (i >= modules.size()) - throw sls::RuntimeError("Module out of range"); + throw RuntimeError("Module out of range"); futures.push_back(std::async(std::launch::async, somefunc, modules[i].get(), Args...)); } - sls::Result result; + Result result; result.reserve(positions.size()); for (auto &i : futures) { result.push_back(i.get()); @@ -144,12 +142,12 @@ class DetectorImpl : public virtual slsDetectorDefs { } template - void Parallel(void (sls::Module::*somefunc)(CT...), + void Parallel(void (Module::*somefunc)(CT...), std::vector positions, typename NonDeduced::type... Args) { if (modules.empty()) - throw sls::RuntimeError("No modules added"); + throw RuntimeError("No modules added"); if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { positions.resize(modules.size()); @@ -159,7 +157,7 @@ class DetectorImpl : public virtual slsDetectorDefs { futures.reserve(positions.size()); for (size_t i : positions) { if (i >= modules.size()) - throw sls::RuntimeError("Module out of range"); + throw RuntimeError("Module out of range"); futures.push_back(std::async(std::launch::async, somefunc, modules[i].get(), Args...)); } @@ -169,12 +167,12 @@ class DetectorImpl : public virtual slsDetectorDefs { } template - void Parallel(void (sls::Module::*somefunc)(CT...) const, + void Parallel(void (Module::*somefunc)(CT...) const, std::vector positions, typename NonDeduced::type... Args) const { if (modules.empty()) - throw sls::RuntimeError("No modules added"); + throw RuntimeError("No modules added"); if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { positions.resize(modules.size()); @@ -184,7 +182,7 @@ class DetectorImpl : public virtual slsDetectorDefs { futures.reserve(positions.size()); for (size_t i : positions) { if (i >= modules.size()) - throw sls::RuntimeError("Module out of range"); + throw RuntimeError("Module out of range"); futures.push_back(std::async(std::launch::async, somefunc, modules[i].get(), Args...)); } @@ -298,7 +296,7 @@ class DetectorImpl : public virtual slsDetectorDefs { std::vector readProgrammingFile(const std::string &fname); void setNumberofUDPInterfaces(int n, Positions pos); - sls::Result getDefaultDac(defs::dacIndex index, + Result getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, Positions pos = {}); void setDefaultDac(defs::dacIndex index, int defaultValue, @@ -396,9 +394,9 @@ class DetectorImpl : public virtual slsDetectorDefs { defs::xy calculatePosition(int moduleIndex, defs::xy geometry) const; const int detectorIndex{0}; - sls::SharedMemory shm{0, -1}; - sls::SharedMemory ctb_shm{0, -1, CtbConfig::shm_tag()}; - std::vector> modules; + SharedMemory shm{0, -1}; + SharedMemory ctb_shm{0, -1, CtbConfig::shm_tag()}; + std::vector> modules; /** data streaming (down stream) enabled in client (zmq sckets created) */ bool client_downstream{false}; diff --git a/slsDetectorSoftware/src/HelpDacs.h b/slsDetectorSoftware/src/HelpDacs.h index 236167838..73fbad429 100644 --- a/slsDetectorSoftware/src/HelpDacs.h +++ b/slsDetectorSoftware/src/HelpDacs.h @@ -2,6 +2,8 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #include "sls/string_utils.h" +namespace sls { + std::string GetHelpDac(std::string dac) { if (sls::is_int(dac)) { return std::string("[dac name] [dac or mV value] [(optional unit) mV] " @@ -303,4 +305,6 @@ std::string GetHelpDac(std::string dac) { // clang-format on throw sls::RuntimeError("Unknown dac command"); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ef23359de..3ec7c22ca 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -68,7 +68,7 @@ std::string Module::getHostname() const { return shm()->hostname; } void Module::setHostname(const std::string &hostname, const bool initialChecks) { - sls::strcpy_safe(shm()->hostname, hostname.c_str()); + strcpy_safe(shm()->hostname, hostname.c_str()); auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.close(); try { @@ -117,7 +117,7 @@ int64_t Module::getReceiverSoftwareVersion() const { slsDetectorDefs::detectorType Module::getTypeFromDetector(const std::string &hostname, int cport) { LOG(logDEBUG1) << "Getting Module type "; - sls::ClientSocket socket("Detector", hostname, cport); + ClientSocket socket("Detector", hostname, cport); socket.Send(F_GET_DETECTOR_TYPE); socket.Receive(); // TODO! Should we look at this OK/FAIL? auto retval = socket.Receive(); @@ -443,7 +443,7 @@ std::string Module::getSettingsDir() const { } std::string Module::setSettingsDir(const std::string &dir) { - sls::strcpy_safe(shm()->settingsDir, dir.c_str()); + strcpy_safe(shm()->settingsDir, dir.c_str()); return shm()->settingsDir; } @@ -894,7 +894,7 @@ std::vector Module::getFramesCaughtByReceiver() const { std::vector retval(nports); client.Receive(retval); LOG(logDEBUG1) << "Frames caught of Receiver" << moduleIndex << ": " - << sls::ToString(retval); + << ToString(retval); return retval; } } @@ -916,7 +916,7 @@ std::vector Module::getNumMissingPackets() const { std::vector retval(nports); client.Receive(retval); LOG(logDEBUG1) << "Missing packets of Receiver" << moduleIndex - << ": " << sls::ToString(retval); + << ": " << ToString(retval); return retval; } } @@ -938,7 +938,7 @@ std::vector Module::getReceiverCurrentFrameIndex() const { std::vector retval(nports); client.Receive(retval); LOG(logDEBUG1) << "Frame index of Receiver" << moduleIndex << ": " - << sls::ToString(retval); + << ToString(retval); return retval; } } @@ -1002,8 +1002,8 @@ void Module::selectUDPInterface(int n) { sendToDetector(F_SET_INTERFACE_SEL, n, nullptr); } -sls::IpAddr Module::getSourceUDPIP() const { - return sendToDetector(F_GET_SOURCE_UDP_IP); +IpAddr Module::getSourceUDPIP() const { + return sendToDetector(F_GET_SOURCE_UDP_IP); } void Module::setSourceUDPIP(const IpAddr ip) { @@ -1013,8 +1013,8 @@ void Module::setSourceUDPIP(const IpAddr ip) { sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr); } -sls::IpAddr Module::getSourceUDPIP2() const { - return sendToDetector(F_GET_SOURCE_UDP_IP2); +IpAddr Module::getSourceUDPIP2() const { + return sendToDetector(F_GET_SOURCE_UDP_IP2); } void Module::setSourceUDPIP2(const IpAddr ip) { @@ -1024,33 +1024,33 @@ void Module::setSourceUDPIP2(const IpAddr ip) { sendToDetector(F_SET_SOURCE_UDP_IP2, ip, nullptr); } -sls::MacAddr Module::getSourceUDPMAC() const { - return sendToDetector(F_GET_SOURCE_UDP_MAC); +MacAddr Module::getSourceUDPMAC() const { + return sendToDetector(F_GET_SOURCE_UDP_MAC); } -void Module::setSourceUDPMAC(const sls::MacAddr mac) { +void Module::setSourceUDPMAC(const MacAddr mac) { if (mac == 0) { throw RuntimeError("Invalid source udp mac address"); } sendToDetector(F_SET_SOURCE_UDP_MAC, mac, nullptr); } -sls::MacAddr Module::getSourceUDPMAC2() const { - return sendToDetector(F_GET_SOURCE_UDP_MAC2); +MacAddr Module::getSourceUDPMAC2() const { + return sendToDetector(F_GET_SOURCE_UDP_MAC2); } -void Module::setSourceUDPMAC2(const sls::MacAddr mac) { +void Module::setSourceUDPMAC2(const MacAddr mac) { if (mac == 0) { throw RuntimeError("Invalid source udp mac address2"); } sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr); } -sls::UdpDestination Module::getDestinationUDPList(const uint32_t entry) const { - return sendToDetector(F_GET_DEST_UDP_LIST, entry); +UdpDestination Module::getDestinationUDPList(const uint32_t entry) const { + return sendToDetector(F_GET_DEST_UDP_LIST, entry); } -void Module::setDestinationUDPList(const sls::UdpDestination dest) { +void Module::setDestinationUDPList(const UdpDestination dest) { // set them in the default way so the receivers are also set up if (dest.entry == 0) { if (dest.port != 0) { @@ -1090,8 +1090,8 @@ void Module::setFirstUDPDestination(const int value) { sendToDetector(F_SET_UDP_FIRST_DEST, value, nullptr); } -sls::IpAddr Module::getDestinationUDPIP() const { - return sendToDetector(F_GET_DEST_UDP_IP); +IpAddr Module::getDestinationUDPIP() const { + return sendToDetector(F_GET_DEST_UDP_IP); } void Module::setDestinationUDPIP(const IpAddr ip) { @@ -1104,7 +1104,7 @@ void Module::setDestinationUDPIP(const IpAddr ip) { } sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr); if (shm()->useReceiverFlag) { - sls::MacAddr retval(0LU); + MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); LOG(logINFO) << "Setting destination udp mac of Module " << moduleIndex << " to " << retval; @@ -1112,8 +1112,8 @@ void Module::setDestinationUDPIP(const IpAddr ip) { } } -sls::IpAddr Module::getDestinationUDPIP2() const { - return sendToDetector(F_GET_DEST_UDP_IP2); +IpAddr Module::getDestinationUDPIP2() const { + return sendToDetector(F_GET_DEST_UDP_IP2); } void Module::setDestinationUDPIP2(const IpAddr ip) { @@ -1127,7 +1127,7 @@ void Module::setDestinationUDPIP2(const IpAddr ip) { } sendToDetector(F_SET_DEST_UDP_IP2, ip, nullptr); if (shm()->useReceiverFlag) { - sls::MacAddr retval(0LU); + MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); LOG(logINFO) << "Setting destination udp mac2 of Module " << moduleIndex << " to " << retval; @@ -1135,8 +1135,8 @@ void Module::setDestinationUDPIP2(const IpAddr ip) { } } -sls::MacAddr Module::getDestinationUDPMAC() const { - return sendToDetector(F_GET_DEST_UDP_MAC); +MacAddr Module::getDestinationUDPMAC() const { + return sendToDetector(F_GET_DEST_UDP_MAC); } void Module::setDestinationUDPMAC(const MacAddr mac) { @@ -1146,8 +1146,8 @@ void Module::setDestinationUDPMAC(const MacAddr mac) { sendToDetector(F_SET_DEST_UDP_MAC, mac, nullptr); } -sls::MacAddr Module::getDestinationUDPMAC2() const { - return sendToDetector(F_GET_DEST_UDP_MAC2); +MacAddr Module::getDestinationUDPMAC2() const { + return sendToDetector(F_GET_DEST_UDP_MAC2); } void Module::setDestinationUDPMAC2(const MacAddr mac) { @@ -1279,19 +1279,19 @@ void Module::setReceiverHostname(const std::string &receiverIP) { if (receiverIP == "none") { memset(shm()->rxHostname, 0, MAX_STR_LENGTH); - sls::strcpy_safe(shm()->rxHostname, "none"); + strcpy_safe(shm()->rxHostname, "none"); shm()->useReceiverFlag = false; return; } // start updating std::string host = receiverIP; - auto res = sls::split(host, ':'); + auto res = split(host, ':'); if (res.size() > 1) { host = res[0]; shm()->rxTCPPort = std::stoi(res[1]); } - sls::strcpy_safe(shm()->rxHostname, host.c_str()); + strcpy_safe(shm()->rxHostname, host.c_str()); shm()->useReceiverFlag = true; checkReceiverVersionCompatibility(); @@ -1307,7 +1307,7 @@ void Module::setReceiverHostname(const std::string &receiverIP) { memset(retval.hostname, 0, sizeof(retval.hostname)); strcpy_safe(retval.hostname, shm()->hostname); - sls::MacAddr retvals[2]; + MacAddr retvals[2]; sendToReceiver(F_SETUP_RECEIVER, retval, retvals); // update Modules with dest mac if (retval.udp_dstmac == 0 && retvals[0] != 0) { @@ -1393,8 +1393,8 @@ void Module::setReceiverLock(bool lock) { sendToReceiver(F_LOCK_RECEIVER, static_cast(lock)); } -sls::IpAddr Module::getReceiverLastClientIP() const { - return sendToReceiver(F_GET_LAST_RECEIVER_CLIENT_IP); +IpAddr Module::getReceiverLastClientIP() const { + return sendToReceiver(F_GET_LAST_RECEIVER_CLIENT_IP); } std::array Module::getReceiverThreadIds() const { @@ -1443,7 +1443,7 @@ void Module::setFilePath(const std::string &path) { throw RuntimeError("Cannot set empty file path"); } char args[MAX_STR_LENGTH]{}; - sls::strcpy_safe(args, path.c_str()); + strcpy_safe(args, path.c_str()); sendToReceiver(F_SET_RECEIVER_FILE_PATH, args, nullptr); } @@ -1458,7 +1458,7 @@ void Module::setFileName(const std::string &fname) { throw RuntimeError("Cannot set empty file name prefix"); } char args[MAX_STR_LENGTH]{}; - sls::strcpy_safe(args, fname.c_str()); + strcpy_safe(args, fname.c_str()); sendToReceiver(F_SET_RECEIVER_FILE_NAME, args, nullptr); } @@ -1555,11 +1555,11 @@ void Module::setReceiverStreamingPort(int port) { sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr); } -sls::IpAddr Module::getReceiverStreamingIP() const { - return sendToReceiver(F_GET_RECEIVER_STREAMING_SRC_IP); +IpAddr Module::getReceiverStreamingIP() const { + return sendToReceiver(F_GET_RECEIVER_STREAMING_SRC_IP); } -void Module::setReceiverStreamingIP(const sls::IpAddr ip) { +void Module::setReceiverStreamingIP(const IpAddr ip) { if (ip == 0) { throw RuntimeError("Invalid receiver zmq ip address"); } @@ -1574,9 +1574,9 @@ int Module::getClientStreamingPort() const { return shm()->zmqport; } void Module::setClientStreamingPort(int port) { shm()->zmqport = port; } -sls::IpAddr Module::getClientStreamingIP() const { return shm()->zmqip; } +IpAddr Module::getClientStreamingIP() const { return shm()->zmqip; } -void Module::setClientStreamingIP(const sls::IpAddr ip) { +void Module::setClientStreamingIP(const IpAddr ip) { if (ip == 0) { throw RuntimeError("Invalid client zmq ip address"); } @@ -2420,18 +2420,18 @@ void Module::setExternalSampling(bool value) { } std::vector Module::getReceiverDbitList() const { - return sendToReceiver>( + return sendToReceiver>( F_GET_RECEIVER_DBIT_LIST); } void Module::setReceiverDbitList(std::vector list) { LOG(logDEBUG1) << "Setting Receiver Dbit List"; if (list.size() > 64) { - throw sls::RuntimeError("Dbit list size cannot be greater than 64\n"); + throw RuntimeError("Dbit list size cannot be greater than 64\n"); } for (auto &it : list) { if (it < 0 || it > 63) { - throw sls::RuntimeError( + throw RuntimeError( "Dbit list value must be between 0 and 63\n"); } } @@ -2439,7 +2439,7 @@ void Module::setReceiverDbitList(std::vector list) { auto last = std::unique(begin(list), end(list)); list.erase(last, list.end()); - sls::StaticVector arg = list; + StaticVector arg = list; sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); } @@ -2628,7 +2628,7 @@ void Module::setAdditionalJsonHeader( std::string Module::getAdditionalJsonParameter(const std::string &key) const { char arg[SHORT_STR_LENGTH]{}; - sls::strcpy_safe(arg, key.c_str()); + strcpy_safe(arg, key.c_str()); char retval[SHORT_STR_LENGTH]{}; sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval); return retval; @@ -2644,8 +2644,8 @@ void Module::setAdditionalJsonParameter(const std::string &key, "Key cannot be empty. Both can have max 2 characters"); } char args[2][SHORT_STR_LENGTH]{}; - sls::strcpy_safe(args[0], key.c_str()); - sls::strcpy_safe(args[1], value.c_str()); + strcpy_safe(args[0], key.c_str()); + strcpy_safe(args[1], value.c_str()); sendToReceiver(F_SET_ADDITIONAL_JSON_PARAMETER, args, nullptr); } @@ -2797,14 +2797,14 @@ void Module::setLockDetector(bool lock) { sendToDetector(F_LOCK_SERVER, static_cast(lock)); } -sls::IpAddr Module::getLastClientIP() const { - return sendToDetector(F_GET_LAST_CLIENT_IP); +IpAddr Module::getLastClientIP() const { + return sendToDetector(F_GET_LAST_CLIENT_IP); } std::string Module::executeCommand(const std::string &cmd) { char arg[MAX_STR_LENGTH]{}; char retval[MAX_STR_LENGTH]{}; - sls::strcpy_safe(arg, cmd.c_str()); + strcpy_safe(arg, cmd.c_str()); LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname << "): Sending command " << cmd; auto client = DetectorSocket(shm()->hostname, shm()->controlPort); @@ -3254,8 +3254,8 @@ void Module::initializeModuleStructure(detectorType type) { shm()->numberOfModule.y = 0; shm()->controlPort = DEFAULT_PORTNO; shm()->stopPort = DEFAULT_PORTNO + 1; - sls::strcpy_safe(shm()->settingsDir, getenv("HOME")); - sls::strcpy_safe(shm()->rxHostname, "none"); + strcpy_safe(shm()->settingsDir, getenv("HOME")); + strcpy_safe(shm()->rxHostname, "none"); shm()->rxTCPPort = DEFAULT_PORTNO + 2; shm()->useReceiverFlag = false; shm()->numUDPInterfaces = 1; @@ -3310,7 +3310,7 @@ void Module::checkReceiverVersionCompatibility() { sendToReceiver(F_RECEIVER_CHECK_VERSION, int64_t(APIRECEIVER), nullptr); } -int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) { +int Module::sendModule(sls_detector_module *myMod, ClientSocket &client) { constexpr TLogLevel level = logDEBUG1; LOG(level) << "Sending Module"; int ts = 0; @@ -3381,7 +3381,7 @@ void Module::updateReceiverStreamingIP() { auto ip = getReceiverStreamingIP(); if (ip == 0) { // Hostname could be ip try to decode otherwise look up the hostname - ip = sls::IpAddr{shm()->rxHostname}; + ip = IpAddr{shm()->rxHostname}; if (ip == 0) { ip = HostnameToIp(shm()->rxHostname); } @@ -3634,7 +3634,7 @@ void Module::sendProgram(bool blackfin, std::vector buffer, client.Send(filesize); // send checksum - std::string checksum = sls::md5_calculate_checksum(buffer.data(), filesize); + std::string checksum = md5_calculate_checksum(buffer.data(), filesize); LOG(logDEBUG1) << "Checksum:" << checksum; char cChecksum[MAX_STR_LENGTH] = {0}; strcpy(cChecksum, checksum.c_str()); diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f3bd6bc55..818d330df 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -14,13 +14,13 @@ #include #include +namespace sls { + class ServerInterface; #define MODULE_SHMAPIVERSION 0x190726 #define MODULE_SHMVERSION 0x200402 -namespace sls { - /** * @short structure allocated in shared memory to store Module settings for * IPC and cache @@ -40,7 +40,7 @@ struct sharedModule { int stopPort; char settingsDir[MAX_STR_LENGTH]; /** list of the energies at which the Module has been trimmed */ - sls::StaticVector trimEnergies; + StaticVector trimEnergies; /** number of channels per chip */ slsDetectorDefs::xy nChan; slsDetectorDefs::xy nChip; @@ -52,7 +52,7 @@ struct sharedModule { /** Listening tcp port from gui (only data) */ int zmqport; /** Listening tcp ip address from gui (only data) **/ - sls::IpAddr zmqip; + IpAddr zmqip; int numUDPInterfaces; /** to inform rxr when stopping rxr */ bool stoppedFlag; @@ -223,28 +223,28 @@ class Module : public virtual slsDetectorDefs { void setNumberofUDPInterfaces(int n); int getSelectedUDPInterface() const; void selectUDPInterface(int n); - sls::IpAddr getSourceUDPIP() const; - void setSourceUDPIP(const sls::IpAddr ip); - sls::IpAddr getSourceUDPIP2() const; - void setSourceUDPIP2(const sls::IpAddr ip); - sls::MacAddr getSourceUDPMAC() const; - void setSourceUDPMAC(const sls::MacAddr mac); - sls::MacAddr getSourceUDPMAC2() const; - void setSourceUDPMAC2(const sls::MacAddr mac); - sls::UdpDestination getDestinationUDPList(const uint32_t entry) const; - void setDestinationUDPList(const sls::UdpDestination dest); + IpAddr getSourceUDPIP() const; + void setSourceUDPIP(const IpAddr ip); + IpAddr getSourceUDPIP2() const; + void setSourceUDPIP2(const IpAddr ip); + MacAddr getSourceUDPMAC() const; + void setSourceUDPMAC(const MacAddr mac); + MacAddr getSourceUDPMAC2() const; + void setSourceUDPMAC2(const MacAddr mac); + UdpDestination getDestinationUDPList(const uint32_t entry) const; + void setDestinationUDPList(const UdpDestination dest); int getNumberofUDPDestinations() const; void clearUDPDestinations(); int getFirstUDPDestination() const; void setFirstUDPDestination(const int value); - sls::IpAddr getDestinationUDPIP() const; - void setDestinationUDPIP(const sls::IpAddr ip); - sls::IpAddr getDestinationUDPIP2() const; - void setDestinationUDPIP2(const sls::IpAddr ip); - sls::MacAddr getDestinationUDPMAC() const; - void setDestinationUDPMAC(const sls::MacAddr mac); - sls::MacAddr getDestinationUDPMAC2() const; - void setDestinationUDPMAC2(const sls::MacAddr mac); + IpAddr getDestinationUDPIP() const; + void setDestinationUDPIP(const IpAddr ip); + IpAddr getDestinationUDPIP2() const; + void setDestinationUDPIP2(const IpAddr ip); + MacAddr getDestinationUDPMAC() const; + void setDestinationUDPMAC(const MacAddr mac); + MacAddr getDestinationUDPMAC2() const; + void setDestinationUDPMAC2(const MacAddr mac); int getDestinationUDPPort() const; void setDestinationUDPPort(int udpport); int getDestinationUDPPort2() const; @@ -286,7 +286,7 @@ class Module : public virtual slsDetectorDefs { void setReceiverUDPSocketBufferSize(int udpsockbufsize); bool getReceiverLock() const; void setReceiverLock(bool lock); - sls::IpAddr getReceiverLastClientIP() const; + IpAddr getReceiverLastClientIP() const; std::array getReceiverThreadIds() const; bool getRxArping() const; void setRxArping(bool enable); @@ -334,12 +334,12 @@ class Module : public virtual slsDetectorDefs { void setReceiverStreamingStartingFrame(int fnum); int getReceiverStreamingPort() const; void setReceiverStreamingPort(int port); - sls::IpAddr getReceiverStreamingIP() const; - void setReceiverStreamingIP(const sls::IpAddr ip); + IpAddr getReceiverStreamingIP() const; + void setReceiverStreamingIP(const IpAddr ip); int getClientStreamingPort() const; void setClientStreamingPort(int port); - sls::IpAddr getClientStreamingIP() const; - void setClientStreamingIP(const sls::IpAddr ip); + IpAddr getClientStreamingIP() const; + void setClientStreamingIP(const IpAddr ip); int getReceiverStreamingHwm() const; void setReceiverStreamingHwm(const int limit); @@ -589,7 +589,7 @@ class Module : public virtual slsDetectorDefs { void setStopPort(int port_number); bool getLockDetector() const; void setLockDetector(bool lock); - sls::IpAddr getLastClientIP() const; + IpAddr getLastClientIP() const; std::string executeCommand(const std::string &cmd); int64_t getNumberOfFramesFromStart() const; int64_t getActualTime() const; @@ -736,7 +736,7 @@ class Module : public virtual slsDetectorDefs { void checkDetectorVersionCompatibility(); void checkReceiverVersionCompatibility(); void setModule(sls_detector_module &module, bool trimbits = true); - int sendModule(sls_detector_module *myMod, sls::ClientSocket &client); + int sendModule(sls_detector_module *myMod, ClientSocket &client); void updateReceiverStreamingIP(); void updateRateCorrection(); @@ -778,7 +778,7 @@ class Module : public virtual slsDetectorDefs { const int timeRequired); const int moduleIndex; - mutable sls::SharedMemory shm{0, 0}; + mutable SharedMemory shm{0, 0}; static const int BLACKFIN_ERASE_FLASH_TIME = 65; static const int BLACKFIN_WRITE_TO_FLASH_TIME = 30; static const int NIOS_ERASE_FLASH_TIME_FPGA = 10; diff --git a/slsDetectorSoftware/src/SharedMemory.h b/slsDetectorSoftware/src/SharedMemory.h index 2b1135724..63e3b0c41 100644 --- a/slsDetectorSoftware/src/SharedMemory.h +++ b/slsDetectorSoftware/src/SharedMemory.h @@ -13,7 +13,6 @@ #include "sls/logger.h" #include "sls/sls_detector_exceptions.h" -// #include "stdlib.h" #include #include // errno #include // strerror @@ -23,16 +22,15 @@ #include // shared memory #include // fstat #include - -#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_" -#define SHM_MODULE_PREFIX "_module_" -#define SHM_ENV_NAME "SLSDETNAME" - #include #include namespace sls { +#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_" +#define SHM_MODULE_PREFIX "_module_" +#define SHM_ENV_NAME "SLSDETNAME" + template class SharedMemory { static constexpr int NAME_MAX_LENGTH = 255; std::string name; diff --git a/slsReceiverSoftware/include/sls/Receiver.h b/slsReceiverSoftware/include/sls/Receiver.h index 02901c2d3..6fc898cb9 100644 --- a/slsReceiverSoftware/include/sls/Receiver.h +++ b/slsReceiverSoftware/include/sls/Receiver.h @@ -4,10 +4,11 @@ #include "sls/sls_detector_defs.h" #include -class ClientInterface; namespace sls { +class ClientInterface; + class Receiver : private virtual slsDetectorDefs { public: diff --git a/slsReceiverSoftware/src/Arping.cpp b/slsReceiverSoftware/src/Arping.cpp index ac7344025..a946f636f 100644 --- a/slsReceiverSoftware/src/Arping.cpp +++ b/slsReceiverSoftware/src/Arping.cpp @@ -6,6 +6,8 @@ #include #include +namespace sls { + // gettid added in glibc 2.30 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 #include @@ -16,7 +18,7 @@ void Arping::SetInterfacesAndIps(const int index, const std::string &interface, const std::string &ip) { if (interface.empty() || ip.empty()) { - throw sls::RuntimeError("Could not arping. Interface name and ip not " + throw RuntimeError("Could not arping. Interface name and ip not " "set up for interface " + std::to_string(index)); } @@ -38,7 +40,7 @@ void Arping::StartThread() { try { t = std::thread(&Arping::ThreadExecution, this); } catch (...) { - throw sls::RuntimeError("Could not start arping thread"); + throw RuntimeError("Could not start arping thread"); } runningFlag = true; } @@ -74,13 +76,13 @@ void Arping::ThreadExecution() { void Arping::TestCommands() { // atleast one interface must be set up if (commands[0].empty()) { - throw sls::RuntimeError( + throw RuntimeError( "Could not arping. Interface not set up in apring thread"); } // test if arping commands throw an error std::string error = ExecuteCommands(); if (!error.empty()) { - throw sls::RuntimeError(error); + throw RuntimeError(error); } } @@ -117,4 +119,6 @@ std::string Arping::ExecuteCommands() { } return std::string(); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsReceiverSoftware/src/Arping.h b/slsReceiverSoftware/src/Arping.h index 3c84a398b..5fe30068c 100644 --- a/slsReceiverSoftware/src/Arping.h +++ b/slsReceiverSoftware/src/Arping.h @@ -12,6 +12,8 @@ is listening to. #include #include +namespace sls { + class Arping { public: @@ -33,3 +35,6 @@ class Arping { std::thread t; std::atomic threadId{0}; }; + +} // namespace sls + diff --git a/slsReceiverSoftware/src/BinaryDataFile.cpp b/slsReceiverSoftware/src/BinaryDataFile.cpp index 99bf2e42e..98103068a 100644 --- a/slsReceiverSoftware/src/BinaryDataFile.cpp +++ b/slsReceiverSoftware/src/BinaryDataFile.cpp @@ -2,6 +2,8 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #include "BinaryDataFile.h" +namespace sls { + BinaryDataFile::BinaryDataFile(const int index) : File(BINARY), index_(index) {} BinaryDataFile::~BinaryDataFile() { CloseFile(); } @@ -47,12 +49,12 @@ void BinaryDataFile::CreateFile() { if (!overWriteEnable_) { if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "wx"))) { fd_ = nullptr; - throw sls::RuntimeError("Could not create/overwrite file " + + throw RuntimeError("Could not create/overwrite file " + fileName_); } } else if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "w"))) { fd_ = nullptr; - throw sls::RuntimeError("Could not create file " + fileName_); + throw RuntimeError("Could not create file " + fileName_); } // setting to no file buffering setvbuf(fd_, nullptr, _IONBF, 0); @@ -103,8 +105,10 @@ void BinaryDataFile::WriteToFile(char *buffer, const int buffersize, // if write error if (ret != buffersize) { - throw sls::RuntimeError(std::to_string(index_) + + throw RuntimeError(std::to_string(index_) + " : Write to file failed for image number " + std::to_string(currentFrameNumber)); } -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsReceiverSoftware/src/BinaryDataFile.h b/slsReceiverSoftware/src/BinaryDataFile.h index f129050a6..b2de445de 100644 --- a/slsReceiverSoftware/src/BinaryDataFile.h +++ b/slsReceiverSoftware/src/BinaryDataFile.h @@ -4,6 +4,8 @@ #include "File.h" +namespace sls { + class BinaryDataFile : private virtual slsDetectorDefs, public File { public: @@ -42,4 +44,6 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File { int numUnitsPerReadout_{0}; uint32_t udpPortNumber_{0}; uint32_t maxFramesPerFile_{0}; -}; \ No newline at end of file +}; + +} // namespace sls diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index c888d08ba..280ed77a9 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -22,10 +22,11 @@ #include #include + +namespace sls { + using ns = std::chrono::nanoseconds; -using sls::RuntimeError; -using sls::SocketError; -using Interface = sls::ServerInterface; +using Interface = ServerInterface; // gettid added in glibc 2.30 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 @@ -33,6 +34,7 @@ using Interface = sls::ServerInterface; #define gettid() syscall(SYS_gettid) #endif + ClientInterface::~ClientInterface() { killTcpThread = true; LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber; @@ -48,7 +50,7 @@ ClientInterface::ClientInterface(int portNumber) functionTable(); parentThreadId = gettid(); tcpThread = - sls::make_unique(&ClientInterface::startTCPServer, this); + make_unique(&ClientInterface::startTCPServer, this); } int64_t ClientInterface::getReceiverVersion() { return APIRECEIVER; } @@ -98,7 +100,7 @@ void ClientInterface::startTCPServer() { } catch (const RuntimeError &e) { // We had an error needs to be sent to client char mess[MAX_STR_LENGTH]{}; - sls::strcpy_safe(mess, e.what()); + strcpy_safe(mess, e.what()); socket.Send(FAIL); socket.Send(mess); } @@ -277,7 +279,7 @@ void ClientInterface::validate(T arg, T retval, const std::string &modename, void ClientInterface::verifyLock() { if (lockedByClient && server.getThisClient() != server.getLockedBy()) { - throw sls::SocketError("Receiver locked\n"); + throw SocketError("Receiver locked\n"); } } @@ -287,7 +289,7 @@ void ClientInterface::verifyIdle(Interface &socket) { oss << "Can not execute " << getFunctionNameFromEnum((enum detFuncs)fnum) << " when receiver is not idle"; - throw sls::SocketError(oss.str()); + throw SocketError(oss.str()); } } @@ -299,7 +301,7 @@ int ClientInterface::lock_receiver(Interface &socket) { (server.getLockedBy() == server.getThisClient())) { lockedByClient = lock; lock ? server.setLockedBy(server.getThisClient()) - : server.setLockedBy(sls::IpAddr{}); + : server.setLockedBy(IpAddr{}); } else { throw RuntimeError("Receiver locked\n"); } @@ -317,7 +319,7 @@ int ClientInterface::get_version(Interface &socket) { int ClientInterface::setup_receiver(Interface &socket) { auto arg = socket.Receive(); - LOG(logDEBUG) << sls::ToString(arg); + LOG(logDEBUG) << ToString(arg); // if object exists, verify unlocked and idle, else only verify lock // (connecting first time) @@ -333,17 +335,17 @@ int ClientInterface::setup_receiver(Interface &socket) { // udp setup // update retvals only if detmac is not the same as in detector - sls::MacAddr retvals[2]; + MacAddr retvals[2]; if (arg.udp_dstip != 0) { - sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip)); - sls::MacAddr detMac{arg.udp_dstmac}; + MacAddr r = setUdpIp(IpAddr(arg.udp_dstip)); + MacAddr detMac{arg.udp_dstmac}; if (detMac != r) { retvals[0] = r; } } if (arg.udp_dstip2 != 0) { - sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2)); - sls::MacAddr detMac{arg.udp_dstmac2}; + MacAddr r = setUdpIp2(IpAddr(arg.udp_dstip2)); + MacAddr detMac{arg.udp_dstmac2}; if (detMac != r) { retvals[1] = r; } @@ -499,7 +501,7 @@ void ClientInterface::setDetectorType(detectorType arg) { try { detType = GENERIC; - receiver = sls::make_unique(arg); + receiver = make_unique(arg); detType = arg; } catch (std::exception &e) { std::ostringstream os; @@ -527,7 +529,7 @@ void ClientInterface::setDetectorType(detectorType arg) { int ClientInterface::set_detector_roi(Interface &socket) { auto arg = socket.Receive(); - LOG(logDEBUG1) << "Set Detector ROI: " << sls::ToString(arg); + LOG(logDEBUG1) << "Set Detector ROI: " << ToString(arg); if (detType != GOTTHARD) functionNotImplemented(); @@ -644,7 +646,7 @@ int ClientInterface::set_exptime(Interface &socket) { socket.Receive(args); int gateIndex = static_cast(args[0]); ns value = std::chrono::nanoseconds(args[1]); - LOG(logDEBUG1) << "Setting exptime to " << sls::ToString(value) + LOG(logDEBUG1) << "Setting exptime to " << ToString(value) << " (gateIndex: " << gateIndex << ")"; switch (gateIndex) { case -1: @@ -683,14 +685,14 @@ int ClientInterface::set_exptime(Interface &socket) { int ClientInterface::set_period(Interface &socket) { auto value = std::chrono::nanoseconds(socket.Receive()); - LOG(logDEBUG1) << "Setting period to " << sls::ToString(value); + LOG(logDEBUG1) << "Setting period to " << ToString(value); impl()->setAcquisitionPeriod(value); return socket.Send(OK); } int ClientInterface::set_subexptime(Interface &socket) { auto value = std::chrono::nanoseconds(socket.Receive()); - LOG(logDEBUG1) << "Setting period to " << sls::ToString(value); + LOG(logDEBUG1) << "Setting period to " << ToString(value); ns subdeadtime = impl()->getSubPeriod() - impl()->getSubExpTime(); impl()->setSubExpTime(value); impl()->setSubPeriod(impl()->getSubExpTime() + subdeadtime); @@ -699,10 +701,10 @@ int ClientInterface::set_subexptime(Interface &socket) { int ClientInterface::set_subdeadtime(Interface &socket) { auto value = std::chrono::nanoseconds(socket.Receive()); - LOG(logDEBUG1) << "Setting sub deadtime to " << sls::ToString(value); + LOG(logDEBUG1) << "Setting sub deadtime to " << ToString(value); impl()->setSubPeriod(value + impl()->getSubExpTime()); LOG(logDEBUG1) << "Setting sub period to " - << sls::ToString(impl()->getSubPeriod()); + << ToString(impl()->getSubPeriod()); return socket.Send(OK); } @@ -773,7 +775,7 @@ int ClientInterface::get_streaming_frequency(Interface &socket) { int ClientInterface::get_status(Interface &socket) { auto retval = impl()->getStatus(); - LOG(logDEBUG1) << "Status:" << sls::ToString(retval); + LOG(logDEBUG1) << "Status:" << ToString(retval); return socket.sendResult(retval); } @@ -795,7 +797,7 @@ int ClientInterface::stop_receiver(Interface &socket) { auto s = impl()->getStatus(); if (s != IDLE) throw RuntimeError("Could not stop receiver. It as it is: " + - sls::ToString(s)); + ToString(s)); return socket.Send(OK); } @@ -856,7 +858,7 @@ int ClientInterface::get_file_index(Interface &socket) { int ClientInterface::get_frame_index(Interface &socket) { auto retval = impl()->getCurrentFrameIndex(); - LOG(logDEBUG1) << "frames index:" << sls::ToString(retval); + LOG(logDEBUG1) << "frames index:" << ToString(retval); auto size = static_cast(retval.size()); socket.Send(OK); socket.Send(size); @@ -866,7 +868,7 @@ int ClientInterface::get_frame_index(Interface &socket) { int ClientInterface::get_missing_packets(Interface &socket) { auto missing_packets = impl()->getNumMissingPackets(); - LOG(logDEBUG1) << "missing packets:" << sls::ToString(missing_packets); + LOG(logDEBUG1) << "missing packets:" << ToString(missing_packets); auto size = static_cast(missing_packets.size()); socket.Send(OK); socket.Send(size); @@ -876,7 +878,7 @@ int ClientInterface::get_missing_packets(Interface &socket) { int ClientInterface::get_frames_caught(Interface &socket) { auto retval = impl()->getFramesCaught(); - LOG(logDEBUG1) << "frames caught:" << sls::ToString(retval); + LOG(logDEBUG1) << "frames caught:" << ToString(retval); auto size = static_cast(retval.size()); socket.Send(OK); socket.Send(size); @@ -1094,7 +1096,7 @@ int ClientInterface::get_streaming_port(Interface &socket) { } int ClientInterface::set_streaming_source_ip(Interface &socket) { - auto ip = socket.Receive(); + auto ip = socket.Receive(); if (ip == 0) throw RuntimeError("Invalid zmq ip " + ip.str()); verifyIdle(socket); @@ -1103,7 +1105,7 @@ int ClientInterface::set_streaming_source_ip(Interface &socket) { } int ClientInterface::get_streaming_source_ip(Interface &socket) { - sls::IpAddr retval = impl()->getStreamingSourceIP(); + IpAddr retval = impl()->getStreamingSourceIP(); LOG(logDEBUG1) << "streaming IP:" << retval; return socket.sendResult(retval); } @@ -1151,14 +1153,14 @@ int ClientInterface::set_additional_json_header(Interface &socket) { } } // verifyIdle(socket); allowing it to be set on the fly - LOG(logDEBUG1) << "Setting additional json header: " << sls::ToString(json); + LOG(logDEBUG1) << "Setting additional json header: " << ToString(json); impl()->setAdditionalJsonHeader(json); return socket.Send(OK); } int ClientInterface::get_additional_json_header(Interface &socket) { std::map json = impl()->getAdditionalJsonHeader(); - LOG(logDEBUG1) << "additional json header:" << sls::ToString(json); + LOG(logDEBUG1) << "additional json header:" << ToString(json); std::ostringstream oss; for (auto &it : json) { oss << it.first << ' ' << it.second << ' '; @@ -1323,7 +1325,7 @@ int ClientInterface::set_adc_mask(Interface &socket) { } int ClientInterface::set_dbit_list(Interface &socket) { - sls::StaticVector args; + StaticVector args; socket.Receive(args); if (detType != CHIPTESTBOARD) functionNotImplemented(); @@ -1340,7 +1342,7 @@ int ClientInterface::set_dbit_list(Interface &socket) { int ClientInterface::get_dbit_list(Interface &socket) { if (detType != CHIPTESTBOARD) functionNotImplemented(); - sls::StaticVector retval; + StaticVector retval; retval = impl()->getDbitList(); LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); return socket.sendResult(retval); @@ -1403,10 +1405,10 @@ int ClientInterface::set_read_n_rows(Interface &socket) { return socket.Send(OK); } -sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) { +MacAddr ClientInterface::setUdpIp(IpAddr arg) { LOG(logINFO) << "Received UDP IP: " << arg; // getting eth - std::string eth = sls::IpToInterfaceName(arg.str()); + std::string eth = IpToInterfaceName(arg.str()); if (eth == "none") { throw RuntimeError("Failed to get udp ethernet interface from IP " + arg.str()); @@ -1425,7 +1427,7 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) { udpips[0] = arg.str(); // get mac address - auto retval = sls::InterfaceNameToMac(eth); + auto retval = InterfaceNameToMac(eth); if (retval == 0 && arg.str() != LOCALHOST_IP) { throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" + eth + ", ip:" + arg.str() + ")\n"); @@ -1435,16 +1437,16 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) { } int ClientInterface::set_udp_ip(Interface &socket) { - auto arg = socket.Receive(); + auto arg = socket.Receive(); verifyIdle(socket); auto retval = setUdpIp(arg); return socket.sendResult(retval); } -sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) { +MacAddr ClientInterface::setUdpIp2(IpAddr arg) { LOG(logINFO) << "Received UDP IP2: " << arg; // getting eth - std::string eth = sls::IpToInterfaceName(arg.str()); + std::string eth = IpToInterfaceName(arg.str()); if (eth == "none") { throw RuntimeError("Failed to get udp ethernet interface2 from IP " + arg.str()); @@ -1460,7 +1462,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) { udpips[1] = arg.str(); // get mac address - auto retval = sls::InterfaceNameToMac(eth); + auto retval = InterfaceNameToMac(eth); if (retval == 0 && arg.str() != LOCALHOST_IP) { throw RuntimeError( "Failed to get udp mac adddress2 to listen to (eth:" + eth + @@ -1471,7 +1473,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) { } int ClientInterface::set_udp_ip2(Interface &socket) { - auto arg = socket.Receive(); + auto arg = socket.Receive(); verifyIdle(socket); if (detType != JUNGFRAU && detType != GOTTHARD2) { throw RuntimeError( @@ -1595,7 +1597,7 @@ int ClientInterface::set_gate_delay(Interface &socket) { socket.Receive(args); int gateIndex = static_cast(args[0]); auto value = std::chrono::nanoseconds(args[1]); - LOG(logDEBUG1) << "Setting gate delay to " << sls::ToString(value) + LOG(logDEBUG1) << "Setting gate delay to " << ToString(value) << " (gateIndex: " << gateIndex << ")"; if (detType != MYTHEN3) { functionNotImplemented(); @@ -1624,7 +1626,7 @@ int ClientInterface::set_gate_delay(Interface &socket) { int ClientInterface::get_thread_ids(Interface &socket) { auto retval = impl()->getThreadIds(); - LOG(logDEBUG1) << "thread ids retval: " << sls::ToString(retval); + LOG(logDEBUG1) << "thread ids retval: " << ToString(retval); return socket.sendResult(retval); } @@ -1663,7 +1665,7 @@ int ClientInterface::set_rate_correct(Interface &socket) { int ClientInterface::set_scan(Interface &socket) { auto arg = socket.Receive(); - LOG(logDEBUG) << "Scan Mode: " << sls::ToString(arg); + LOG(logDEBUG) << "Scan Mode: " << ToString(arg); verifyIdle(socket); impl()->setScan(arg); return socket.Send(OK); @@ -1698,7 +1700,7 @@ int ClientInterface::set_streaming_hwm(Interface &socket) { int ClientInterface::set_all_threshold(Interface &socket) { auto eVs = socket.Receive>(); - LOG(logDEBUG) << "Threshold:" << sls::ToString(eVs); + LOG(logDEBUG) << "Threshold:" << ToString(eVs); if (detType != MYTHEN3) functionNotImplemented(); verifyIdle(socket); @@ -1718,8 +1720,8 @@ int ClientInterface::set_detector_datastream(Interface &socket) { throw RuntimeError("Invalid port type"); } bool enable = static_cast(args[1]); - LOG(logDEBUG1) << "Setting datastream (" << sls::ToString(port) << ") to " - << sls::ToString(enable); + LOG(logDEBUG1) << "Setting datastream (" << ToString(port) << ") to " + << ToString(enable); if (detType != EIGER) functionNotImplemented(); verifyIdle(socket); @@ -1746,7 +1748,7 @@ int ClientInterface::set_arping(Interface &socket) { int ClientInterface::get_receiver_roi(Interface &socket) { auto retval = impl()->getReceiverROI(); - LOG(logDEBUG1) << "Receiver roi retval:" << sls::ToString(retval); + LOG(logDEBUG1) << "Receiver roi retval:" << ToString(retval); return socket.sendResult(retval); } @@ -1754,7 +1756,7 @@ int ClientInterface::set_receiver_roi(Interface &socket) { auto arg = socket.Receive(); if (detType == CHIPTESTBOARD || detType == MOENCH) functionNotImplemented(); - LOG(logDEBUG1) << "Set Receiver ROI: " << sls::ToString(arg); + LOG(logDEBUG1) << "Set Receiver ROI: " << ToString(arg); verifyIdle(socket); try { impl()->setReceiverROI(arg); @@ -1768,7 +1770,7 @@ int ClientInterface::set_receiver_roi_metadata(Interface &socket) { auto arg = socket.Receive(); if (detType == CHIPTESTBOARD || detType == MOENCH) functionNotImplemented(); - LOG(logDEBUG1) << "Set Receiver ROI Metadata: " << sls::ToString(arg); + LOG(logDEBUG1) << "Set Receiver ROI Metadata: " << ToString(arg); verifyIdle(socket); try { impl()->setReceiverROIMetadata(arg); @@ -1776,4 +1778,6 @@ int ClientInterface::set_receiver_roi_metadata(Interface &socket) { throw RuntimeError("Could not set ReceiverROI metadata"); } return socket.Send(OK); -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index a607d09c0..248f60f2a 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -6,16 +6,19 @@ #include "sls/ServerSocket.h" #include "sls/sls_detector_defs.h" #include "sls/sls_detector_funcs.h" -class ServerInterface; #include #include +namespace sls { + +class ServerInterface; + class ClientInterface : private virtual slsDetectorDefs { enum numberMode { DEC, HEX }; detectorType detType; int portNumber{0}; - sls::ServerSocket server; + ServerSocket server; std::unique_ptr receiver; std::unique_ptr tcpThread; int ret{OK}; @@ -53,132 +56,132 @@ class ClientInterface : private virtual slsDetectorDefs { private: void startTCPServer(); int functionTable(); - int decodeFunction(sls::ServerInterface &socket); + int decodeFunction(ServerInterface &socket); void functionNotImplemented(); void modeNotImplemented(const std::string &modename, int mode); template void validate(T arg, T retval, const std::string &modename, numberMode hex); void verifyLock(); - void verifyIdle(sls::ServerInterface &socket); + void verifyIdle(ServerInterface &socket); - int lock_receiver(sls::ServerInterface &socket); - int get_last_client_ip(sls::ServerInterface &socket); - int get_version(sls::ServerInterface &socket); - int setup_receiver(sls::ServerInterface &socket); + int lock_receiver(ServerInterface &socket); + int get_last_client_ip(ServerInterface &socket); + int get_version(ServerInterface &socket); + int setup_receiver(ServerInterface &socket); void setDetectorType(detectorType arg); - int set_detector_roi(sls::ServerInterface &socket); - int set_num_frames(sls::ServerInterface &socket); - int set_num_triggers(sls::ServerInterface &socket); - int set_num_bursts(sls::ServerInterface &socket); - int set_num_add_storage_cells(sls::ServerInterface &socket); - int set_timing_mode(sls::ServerInterface &socket); - int set_burst_mode(sls::ServerInterface &socket); - int set_num_analog_samples(sls::ServerInterface &socket); - int set_num_digital_samples(sls::ServerInterface &socket); - int set_exptime(sls::ServerInterface &socket); - int set_period(sls::ServerInterface &socket); - int set_subexptime(sls::ServerInterface &socket); - int set_subdeadtime(sls::ServerInterface &socket); - int set_dynamic_range(sls::ServerInterface &socket); - int set_streaming_frequency(sls::ServerInterface &socket); - int get_streaming_frequency(sls::ServerInterface &socket); - int get_status(sls::ServerInterface &socket); - int start_receiver(sls::ServerInterface &socket); - int stop_receiver(sls::ServerInterface &socket); - int set_file_dir(sls::ServerInterface &socket); - int get_file_dir(sls::ServerInterface &socket); - int set_file_name(sls::ServerInterface &socket); - int get_file_name(sls::ServerInterface &socket); - int set_file_index(sls::ServerInterface &socket); - int get_file_index(sls::ServerInterface &socket); - int get_frame_index(sls::ServerInterface &socket); - int get_missing_packets(sls::ServerInterface &socket); - int get_frames_caught(sls::ServerInterface &socket); - int set_file_write(sls::ServerInterface &socket); - int get_file_write(sls::ServerInterface &socket); - int set_master_file_write(sls::ServerInterface &socket); - int get_master_file_write(sls::ServerInterface &socket); - int enable_compression(sls::ServerInterface &socket); - int set_overwrite(sls::ServerInterface &socket); - int get_overwrite(sls::ServerInterface &socket); - int enable_tengiga(sls::ServerInterface &socket); - int set_fifo_depth(sls::ServerInterface &socket); - int set_activate(sls::ServerInterface &socket); - int set_streaming(sls::ServerInterface &socket); - int get_streaming(sls::ServerInterface &socket); - int set_streaming_timer(sls::ServerInterface &socket); - int get_flip_rows(sls::ServerInterface &socket); - int set_flip_rows(sls::ServerInterface &socket); - int set_file_format(sls::ServerInterface &socket); - int get_file_format(sls::ServerInterface &socket); - int set_streaming_port(sls::ServerInterface &socket); - int get_streaming_port(sls::ServerInterface &socket); - int set_streaming_source_ip(sls::ServerInterface &socket); - int get_streaming_source_ip(sls::ServerInterface &socket); - int set_silent_mode(sls::ServerInterface &socket); - int get_silent_mode(sls::ServerInterface &socket); - int restream_stop(sls::ServerInterface &socket); - int set_additional_json_header(sls::ServerInterface &socket); - int get_additional_json_header(sls::ServerInterface &socket); - int set_udp_socket_buffer_size(sls::ServerInterface &socket); - int get_real_udp_socket_buffer_size(sls::ServerInterface &socket); - int set_frames_per_file(sls::ServerInterface &socket); - int get_frames_per_file(sls::ServerInterface &socket); - int check_version_compatibility(sls::ServerInterface &socket); - int set_discard_policy(sls::ServerInterface &socket); - int get_discard_policy(sls::ServerInterface &socket); - int set_padding_enable(sls::ServerInterface &socket); - int get_padding_enable(sls::ServerInterface &socket); - int set_readout_mode(sls::ServerInterface &socket); - int set_adc_mask(sls::ServerInterface &socket); - int set_dbit_list(sls::ServerInterface &socket); - int get_dbit_list(sls::ServerInterface &socket); - int set_dbit_offset(sls::ServerInterface &socket); - int get_dbit_offset(sls::ServerInterface &socket); - int set_quad_type(sls::ServerInterface &socket); - int set_read_n_rows(sls::ServerInterface &socket); - sls::MacAddr setUdpIp(sls::IpAddr arg); - int set_udp_ip(sls::ServerInterface &socket); - sls::MacAddr setUdpIp2(sls::IpAddr arg); - int set_udp_ip2(sls::ServerInterface &socket); - int set_udp_port(sls::ServerInterface &socket); - int set_udp_port2(sls::ServerInterface &socket); - int set_num_interfaces(sls::ServerInterface &socket); - int set_adc_mask_10g(sls::ServerInterface &socket); - int set_counter_mask(sls::ServerInterface &socket); - int increment_file_index(sls::ServerInterface &socket); - int set_additional_json_parameter(sls::ServerInterface &socket); - int get_additional_json_parameter(sls::ServerInterface &socket); - int get_progress(sls::ServerInterface &socket); - int set_num_gates(sls::ServerInterface &socket); - int set_gate_delay(sls::ServerInterface &socket); - int get_thread_ids(sls::ServerInterface &socket); - int get_streaming_start_fnum(sls::ServerInterface &socket); - int set_streaming_start_fnum(sls::ServerInterface &socket); - int set_rate_correct(sls::ServerInterface &socket); - int set_scan(sls::ServerInterface &socket); - int set_threshold(sls::ServerInterface &socket); - int get_streaming_hwm(sls::ServerInterface &socket); - int set_streaming_hwm(sls::ServerInterface &socket); - int set_all_threshold(sls::ServerInterface &socket); - int set_detector_datastream(sls::ServerInterface &socket); - int get_arping(sls::ServerInterface &socket); - int set_arping(sls::ServerInterface &socket); - int get_receiver_roi(sls::ServerInterface &socket); - int set_receiver_roi(sls::ServerInterface &socket); - int set_receiver_roi_metadata(sls::ServerInterface &socket); + int set_detector_roi(ServerInterface &socket); + int set_num_frames(ServerInterface &socket); + int set_num_triggers(ServerInterface &socket); + int set_num_bursts(ServerInterface &socket); + int set_num_add_storage_cells(ServerInterface &socket); + int set_timing_mode(ServerInterface &socket); + int set_burst_mode(ServerInterface &socket); + int set_num_analog_samples(ServerInterface &socket); + int set_num_digital_samples(ServerInterface &socket); + int set_exptime(ServerInterface &socket); + int set_period(ServerInterface &socket); + int set_subexptime(ServerInterface &socket); + int set_subdeadtime(ServerInterface &socket); + int set_dynamic_range(ServerInterface &socket); + int set_streaming_frequency(ServerInterface &socket); + int get_streaming_frequency(ServerInterface &socket); + int get_status(ServerInterface &socket); + int start_receiver(ServerInterface &socket); + int stop_receiver(ServerInterface &socket); + int set_file_dir(ServerInterface &socket); + int get_file_dir(ServerInterface &socket); + int set_file_name(ServerInterface &socket); + int get_file_name(ServerInterface &socket); + int set_file_index(ServerInterface &socket); + int get_file_index(ServerInterface &socket); + int get_frame_index(ServerInterface &socket); + int get_missing_packets(ServerInterface &socket); + int get_frames_caught(ServerInterface &socket); + int set_file_write(ServerInterface &socket); + int get_file_write(ServerInterface &socket); + int set_master_file_write(ServerInterface &socket); + int get_master_file_write(ServerInterface &socket); + int enable_compression(ServerInterface &socket); + int set_overwrite(ServerInterface &socket); + int get_overwrite(ServerInterface &socket); + int enable_tengiga(ServerInterface &socket); + int set_fifo_depth(ServerInterface &socket); + int set_activate(ServerInterface &socket); + int set_streaming(ServerInterface &socket); + int get_streaming(ServerInterface &socket); + int set_streaming_timer(ServerInterface &socket); + int get_flip_rows(ServerInterface &socket); + int set_flip_rows(ServerInterface &socket); + int set_file_format(ServerInterface &socket); + int get_file_format(ServerInterface &socket); + int set_streaming_port(ServerInterface &socket); + int get_streaming_port(ServerInterface &socket); + int set_streaming_source_ip(ServerInterface &socket); + int get_streaming_source_ip(ServerInterface &socket); + int set_silent_mode(ServerInterface &socket); + int get_silent_mode(ServerInterface &socket); + int restream_stop(ServerInterface &socket); + int set_additional_json_header(ServerInterface &socket); + int get_additional_json_header(ServerInterface &socket); + int set_udp_socket_buffer_size(ServerInterface &socket); + int get_real_udp_socket_buffer_size(ServerInterface &socket); + int set_frames_per_file(ServerInterface &socket); + int get_frames_per_file(ServerInterface &socket); + int check_version_compatibility(ServerInterface &socket); + int set_discard_policy(ServerInterface &socket); + int get_discard_policy(ServerInterface &socket); + int set_padding_enable(ServerInterface &socket); + int get_padding_enable(ServerInterface &socket); + int set_readout_mode(ServerInterface &socket); + int set_adc_mask(ServerInterface &socket); + int set_dbit_list(ServerInterface &socket); + int get_dbit_list(ServerInterface &socket); + int set_dbit_offset(ServerInterface &socket); + int get_dbit_offset(ServerInterface &socket); + int set_quad_type(ServerInterface &socket); + int set_read_n_rows(ServerInterface &socket); + MacAddr setUdpIp(IpAddr arg); + int set_udp_ip(ServerInterface &socket); + MacAddr setUdpIp2(IpAddr arg); + int set_udp_ip2(ServerInterface &socket); + int set_udp_port(ServerInterface &socket); + int set_udp_port2(ServerInterface &socket); + int set_num_interfaces(ServerInterface &socket); + int set_adc_mask_10g(ServerInterface &socket); + int set_counter_mask(ServerInterface &socket); + int increment_file_index(ServerInterface &socket); + int set_additional_json_parameter(ServerInterface &socket); + int get_additional_json_parameter(ServerInterface &socket); + int get_progress(ServerInterface &socket); + int set_num_gates(ServerInterface &socket); + int set_gate_delay(ServerInterface &socket); + int get_thread_ids(ServerInterface &socket); + int get_streaming_start_fnum(ServerInterface &socket); + int set_streaming_start_fnum(ServerInterface &socket); + int set_rate_correct(ServerInterface &socket); + int set_scan(ServerInterface &socket); + int set_threshold(ServerInterface &socket); + int get_streaming_hwm(ServerInterface &socket); + int set_streaming_hwm(ServerInterface &socket); + int set_all_threshold(ServerInterface &socket); + int set_detector_datastream(ServerInterface &socket); + int get_arping(ServerInterface &socket); + int set_arping(ServerInterface &socket); + int get_receiver_roi(ServerInterface &socket); + int set_receiver_roi(ServerInterface &socket); + int set_receiver_roi_metadata(ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { return receiver.get(); } else { - throw sls::SocketError( + throw SocketError( "Receiver not set up. Please use rx_hostname first.\n"); } } int (ClientInterface::*flist[NUM_REC_FUNCTIONS])( - sls::ServerInterface &socket); + ServerInterface &socket); //***callback parameters*** @@ -198,3 +201,5 @@ class ClientInterface : private virtual slsDetectorDefs { std::vector udpips = std::vector(MAX_NUMBER_OF_LISTENING_THREADS); }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 300399ecb..517f062e5 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -24,6 +24,8 @@ #include #include +namespace sls { + const std::string DataProcessor::typeName_ = "DataProcessor"; DataProcessor::DataProcessor(int index, detectorType detectorType, Fifo *fifo, @@ -65,7 +67,7 @@ void DataProcessor::ResetParametersforNewAcquisition() { currentFrameIndex_ = 0; firstStreamerFrame_ = true; streamCurrentFrame_ = false; - completeImageToStreamBeforeCropping = sls::make_unique(generalData_->imageSize); + completeImageToStreamBeforeCropping = make_unique(generalData_->imageSize); } void DataProcessor::RecordFirstIndex(uint64_t fnum) { @@ -105,7 +107,7 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable, dataFile_ = new BinaryDataFile(index); break; default: - throw sls::RuntimeError( + throw RuntimeError( "Unknown file format (compile with hdf5 flags"); } } @@ -119,7 +121,7 @@ void DataProcessor::CreateFirstFiles( const uint64_t numImages, const uint32_t dynamicRange, const bool detectorDataStream) { if (dataFile_ == nullptr) { - throw sls::RuntimeError("file object not contstructed"); + throw RuntimeError("file object not contstructed"); } CloseFiles(); @@ -154,14 +156,14 @@ void DataProcessor::CreateFirstFiles( modulePos, numUnitsPerReadout, udpPortNumber, maxFramesPerFile); break; default: - throw sls::RuntimeError("Unknown file format (compile with hdf5 flags"); + throw RuntimeError("Unknown file format (compile with hdf5 flags"); } } #ifdef HDF5C uint32_t DataProcessor::GetFilesInAcquisition() const { if (dataFile_ == nullptr) { - throw sls::RuntimeError("No data file object created to get number of " + throw RuntimeError("No data file object created to get number of " "files in acquiistion"); } return dataFile_->GetFilesInAcquisition(); @@ -243,7 +245,7 @@ std::string DataProcessor::CreateMasterFile( filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode, attr); default: - throw sls::RuntimeError("Unknown file format (compile with hdf5 flags"); + throw RuntimeError("Unknown file format (compile with hdf5 flags"); } } @@ -373,7 +375,7 @@ void DataProcessor::ProcessAnImage(char *buf) { (*((uint32_t *)buf)) = revsize; } } catch (const std::exception &e) { - throw sls::RuntimeError("Get Data Callback Error: " + + throw RuntimeError("Get Data Callback Error: " + std::string(e.what())); } @@ -386,7 +388,7 @@ void DataProcessor::ProcessAnImage(char *buf) { (uint32_t)(*((uint32_t *)buf)), //+ size of data (resizable // from previous call back fnum - firstIndex_, nump); - } catch (const sls::RuntimeError &e) { + } catch (const RuntimeError &e) { ; // ignore write exception for now (TODO: send error message // via stopReceiver tcp) } @@ -559,7 +561,7 @@ void DataProcessor::RearrangeDbitData(char *buf) { } void DataProcessor::CropImage(char *buf) { - LOG(logDEBUG) << "Cropping Image to ROI " << sls::ToString(receiverRoi_); + LOG(logDEBUG) << "Cropping Image to ROI " << ToString(receiverRoi_); int nPixelsX = generalData_->nPixelsX; int xmin = receiverRoi_.xmin; int xmax = receiverRoi_.xmax; @@ -598,3 +600,5 @@ void DataProcessor::CropImage(char *buf) { } } } + +} // namespace sls diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 9146a74ba..2e89ec198 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -14,16 +14,18 @@ #include "ThreadObject.h" #include "receiver_defs.h" +#include +#include +#include + +namespace sls { + class GeneralData; class Fifo; class File; class DataStreamer; struct MasterAttributes; -#include -#include -#include - class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { public: @@ -206,3 +208,5 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { void *pRawDataReady{nullptr}; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index fcb2c8d0a..5d89b0126 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -14,6 +14,8 @@ #include #include +namespace sls { + const std::string DataStreamer::TypeName = "DataStreamer"; DataStreamer::DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi, @@ -74,7 +76,7 @@ void DataStreamer::SetAdditionalJsonHeader( } void DataStreamer::CreateZmqSockets(int *nunits, uint32_t port, - const sls::IpAddr ip, int hwm) { + const IpAddr ip, int hwm) { uint32_t portnum = port + index; std::string sip = ip.str(); try { @@ -83,7 +85,7 @@ void DataStreamer::CreateZmqSockets(int *nunits, uint32_t port, if (hwm >= 0) { zmqSocket->SetSendHighWaterMark(hwm); if (zmqSocket->GetSendHighWaterMark() != hwm) { - throw sls::RuntimeError( + throw RuntimeError( "Could not set zmq send high water mark to " + std::to_string(hwm)); } @@ -262,8 +264,10 @@ void DataStreamer::RestreamStop() { zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; int ret = zmqSocket->SendHeader(index, zHeader); if (!ret) { - throw sls::RuntimeError( + throw RuntimeError( "Could not restream Dummy Header via ZMQ for port " + std::to_string(zmqSocket->GetPortNumber())); } } + +} // namespace sls diff --git a/slsReceiverSoftware/src/DataStreamer.h b/slsReceiverSoftware/src/DataStreamer.h index c4c6959c9..49c3c3d81 100644 --- a/slsReceiverSoftware/src/DataStreamer.h +++ b/slsReceiverSoftware/src/DataStreamer.h @@ -12,14 +12,16 @@ #include "ThreadObject.h" #include "sls/network_utils.h" +#include +#include + +namespace sls { + class GeneralData; class Fifo; class DataStreamer; class ZmqSocket; -#include -#include - class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { public: @@ -62,7 +64,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { * @param ip streaming source ip * @param hwm streaming high water mark */ - void CreateZmqSockets(int *nunits, uint32_t port, const sls::IpAddr ip, + void CreateZmqSockets(int *nunits, uint32_t port, const IpAddr ip, int hwm); void CloseZmqSocket(); void RestreamStop(); @@ -131,3 +133,5 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { bool *quadEnable; uint64_t *totalNumFrames; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index 8221831e5..ccb01108d 100644 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -15,6 +15,8 @@ #include #include +namespace sls { + Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth) : index(ind), memory(nullptr), fifoBound(nullptr), fifoFree(nullptr), fifoStream(nullptr), fifoDepth(depth), status_fifoBound(0), @@ -35,14 +37,14 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { DestroyFifos(); // create fifos - fifoBound = new sls::CircularFifo(fifoDepth); - fifoFree = new sls::CircularFifo(fifoDepth); - fifoStream = new sls::CircularFifo(fifoDepth); + fifoBound = new CircularFifo(fifoDepth); + fifoFree = new CircularFifo(fifoDepth); + fifoStream = new CircularFifo(fifoDepth); // allocate memory size_t mem_len = (size_t)fifoItemSize * (size_t)fifoDepth * sizeof(char); memory = (char *)malloc(mem_len); if (memory == nullptr) { - throw sls::RuntimeError("Could not allocate memory for fifos"); + throw RuntimeError("Could not allocate memory for fifos"); } memset(memory, 0, mem_len); int pagesize = getpagesize(); @@ -116,3 +118,5 @@ int Fifo::GetMinLevelForFifoFree() { status_fifoFree = fifoDepth; return temp; } + +} // namespace sls diff --git a/slsReceiverSoftware/src/Fifo.h b/slsReceiverSoftware/src/Fifo.h index c8a98ca0c..c55e6fc9f 100644 --- a/slsReceiverSoftware/src/Fifo.h +++ b/slsReceiverSoftware/src/Fifo.h @@ -16,6 +16,8 @@ #include "sls/CircularFifo.h" +namespace sls { + class Fifo : private virtual slsDetectorDefs { public: @@ -94,13 +96,13 @@ class Fifo : private virtual slsDetectorDefs { char *memory; /** Circular Fifo pointing to addresses of bound data in memory */ - sls::CircularFifo *fifoBound; + CircularFifo *fifoBound; /** Circular Fifo pointing to addresses of freed data in memory */ - sls::CircularFifo *fifoFree; + CircularFifo *fifoFree; /** Circular Fifo pointing to addresses of to be streamed data in memory */ - sls::CircularFifo *fifoStream; + CircularFifo *fifoStream; /** Fifo depth set */ int fifoDepth; @@ -108,3 +110,6 @@ class Fifo : private virtual slsDetectorDefs { volatile int status_fifoBound; volatile int status_fifoFree; }; + +} // namespace sls + diff --git a/slsReceiverSoftware/src/File.cpp b/slsReceiverSoftware/src/File.cpp index 74b587515..2da45d84c 100644 --- a/slsReceiverSoftware/src/File.cpp +++ b/slsReceiverSoftware/src/File.cpp @@ -4,8 +4,12 @@ #include +namespace sls { + File::File(const slsDetectorDefs::fileFormat format) : format_(format) {} File::~File() {} slsDetectorDefs::fileFormat File::GetFileFormat() const { return format_; } + +} // namespace sls diff --git a/slsReceiverSoftware/src/File.h b/slsReceiverSoftware/src/File.h index 9b386a640..c9cebb276 100644 --- a/slsReceiverSoftware/src/File.h +++ b/slsReceiverSoftware/src/File.h @@ -5,7 +5,9 @@ #include "sls/logger.h" #include "sls/sls_detector_defs.h" -struct MasterAttributes; +#include + +namespace sls { #ifdef HDF5C #include "H5Cpp.h" @@ -14,7 +16,7 @@ using namespace H5; #endif #endif -#include +struct MasterAttributes; class File : private virtual slsDetectorDefs { @@ -89,3 +91,5 @@ class File : private virtual slsDetectorDefs { protected: slsDetectorDefs::fileFormat format_; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/GeneralData.h b/slsReceiverSoftware/src/GeneralData.h index 6652b4033..4c71f8f15 100644 --- a/slsReceiverSoftware/src/GeneralData.h +++ b/slsReceiverSoftware/src/GeneralData.h @@ -16,6 +16,8 @@ #include //ceil #include +namespace sls { + class GeneralData { public: @@ -71,7 +73,7 @@ class GeneralData { float GetPixelDepth() { return float(dynamicRange) / 8; } void ThrowGenericError(std::string msg) const { - throw sls::RuntimeError( + throw RuntimeError( msg + std::string("This is a generic function that should be " "overloaded by a derived class")); } @@ -393,7 +395,7 @@ class Mythen3Data : public GeneralData { virtual void SetCounterMask(const int mask) { int n = __builtin_popcount(mask); if (n < 1 || n > 3) { - throw sls::RuntimeError("Invalid number of counters " + + throw RuntimeError("Invalid number of counters " + std::to_string(n) + ". Expected 1-3."); } counterMask = mask; @@ -642,3 +644,5 @@ class MoenchData : public GeneralData { LOG(logDEBUG) << "Databytes: " << imageSize; }; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/HDF5DataFile.cpp b/slsReceiverSoftware/src/HDF5DataFile.cpp index e9b2c9212..2d30b90c3 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.cpp +++ b/slsReceiverSoftware/src/HDF5DataFile.cpp @@ -5,6 +5,8 @@ #include +namespace sls { + HDF5DataFile::HDF5DataFile(int index, std::mutex *hdf5Lib) : File(HDF5), index_(index), hdf5Lib_(hdf5Lib) { @@ -218,7 +220,7 @@ void HDF5DataFile::CreateFile() { } catch (const Exception &error) { error.printErrorStack(); CloseFile(); - throw sls::RuntimeError("Could not create HDF5 handles in object " + + throw RuntimeError("Could not create HDF5 handles in object " + index_); } if (!silentMode_) { @@ -266,7 +268,7 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber, if (dynamicRange_ == 12) { revBuffer = (char *)malloc(EIGER_16_BIT_IMAGE_SIZE); if (revBuffer == nullptr) { - throw sls::RuntimeError("Could not allocate memory for 12 bit to " + throw RuntimeError("Could not allocate memory for 12 bit to " "16 bit conversion in object " + std::to_string(index_)); } @@ -300,7 +302,7 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber, } LOG(logERROR) << "Could not write to file in object " << index_; error.printErrorStack(); - throw sls::RuntimeError("Could not write to file in object " + + throw RuntimeError("Could not write to file in object " + std::to_string(index_)); } } @@ -383,7 +385,7 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber, i = 14; } catch (const Exception &error) { error.printErrorStack(); - throw sls::RuntimeError( + throw RuntimeError( "Could not write parameters (index:" + std::to_string(i) + ") to file in object " + std::to_string(index_)); } @@ -413,7 +415,7 @@ void HDF5DataFile::ExtendDataset() { } catch (const Exception &error) { error.printErrorStack(); - throw sls::RuntimeError("Could not extend dataset in object " + + throw RuntimeError("Could not extend dataset in object " + std::to_string(index_)); } if (!silentMode_) { @@ -421,4 +423,6 @@ void HDF5DataFile::ExtendDataset() { << ", Total x Dimension: " << (extNumImages_ + numImages_); } extNumImages_ += numImages_; -} \ No newline at end of file +} + +} // namespace sls diff --git a/slsReceiverSoftware/src/HDF5DataFile.h b/slsReceiverSoftware/src/HDF5DataFile.h index dc1c2ae5e..7c0805ea7 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.h +++ b/slsReceiverSoftware/src/HDF5DataFile.h @@ -6,6 +6,8 @@ #include +namespace sls { + class HDF5DataFile : private virtual slsDetectorDefs, public File { public: @@ -76,4 +78,6 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File { static const int EIGER_NUM_PIXELS{256 * 2 * 256}; static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2}; -}; \ No newline at end of file +}; + +} // namespace sls diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 968ef29a8..1d0882df6 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -22,6 +22,8 @@ #include #include +namespace sls { + /** cosntructor & destructor */ Implementation::Implementation(const detectorType d) { setDetectorType(d); } @@ -73,12 +75,12 @@ void Implementation::SetupFifoStructure() { // create fifo structure try { - fifo.push_back(sls::make_unique( + fifo.push_back(make_unique( i, datasize + (generalData->fifoBufferHeaderSize), fifoDepth)); } catch (...) { fifo.clear(); fifoDepth = 0; - throw sls::RuntimeError( + throw RuntimeError( "Could not allocate memory for fifo structure " + std::to_string(i) + ". FifoDepth is now 0."); } @@ -117,10 +119,10 @@ void Implementation::setDetectorType(const detectorType d) { case MOENCH: case MYTHEN3: case GOTTHARD2: - LOG(logINFO) << " ***** " << sls::ToString(d) << " Receiver *****"; + LOG(logINFO) << " ***** " << ToString(d) << " Receiver *****"; break; default: - throw sls::RuntimeError("This is an unknown receiver type " + + throw RuntimeError("This is an unknown receiver type " + std::to_string(static_cast(d))); } @@ -176,7 +178,7 @@ void Implementation::setDetectorType(const detectorType d) { try { auto fifo_ptr = fifo[i].get(); - listener.push_back(sls::make_unique( + listener.push_back(make_unique( i, detType, fifo_ptr, &status, &udpPortNum[i], ð[i], &udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode, &detectorDataStream[i], @@ -185,14 +187,14 @@ void Implementation::setDetectorType(const detectorType d) { if (detType == CHIPTESTBOARD) { ctbAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes(); } - dataProcessor.push_back(sls::make_unique( + dataProcessor.push_back(make_unique( i, detType, fifo_ptr, &dataStreamEnable, &streamingFrequency, &streamingTimerInMs, &streamingStartFnum, &framePadding, &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); } catch (...) { listener.clear(); dataProcessor.clear(); - throw sls::RuntimeError( + throw RuntimeError( "Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")"); } @@ -209,7 +211,7 @@ void Implementation::setDetectorType(const detectorType d) { } SetThreadPriorities(); - LOG(logDEBUG) << " Detector type set to " << sls::ToString(d); + LOG(logDEBUG) << " Detector type set to " << ToString(d); } slsDetectorDefs::xy Implementation::getDetectorSize() const { @@ -240,7 +242,7 @@ void Implementation::setDetectorSize(const slsDetectorDefs::xy size) { it->SetNumberofPorts(numPorts); } - LOG(logINFO) << "Detector Size (ports): " << sls::ToString(numPorts); + LOG(logINFO) << "Detector Size (ports): " << ToString(numPorts); } int Implementation::getModulePositionId() const { return modulePos; } @@ -303,7 +305,7 @@ Implementation::getFrameDiscardPolicy() const { void Implementation::setFrameDiscardPolicy(const frameDiscardPolicy i) { frameDiscardMode = i; - LOG(logINFO) << "Frame Discard Policy: " << sls::ToString(frameDiscardMode); + LOG(logINFO) << "Frame Discard Policy: " << ToString(frameDiscardMode); } bool Implementation::getFramePaddingEnable() const { return framePadding; } @@ -406,7 +408,7 @@ void Implementation::setReceiverROI(const slsDetectorDefs::ROI arg) { } } LOG(logDEBUG) - << iPort << ": portfullroi:" << sls::ToString(portFullRoi); + << iPort << ": portfullroi:" << ToString(portFullRoi); // no roi if (arg.xmin > portFullRoi.xmax || @@ -440,15 +442,15 @@ void Implementation::setReceiverROI(const slsDetectorDefs::ROI arg) { } for (size_t i = 0; i != dataProcessor.size(); ++i) dataProcessor[i]->SetReceiverROI(portRois[i]); - LOG(logINFO) << "receiver roi: " << sls::ToString(receiverRoi); + LOG(logINFO) << "receiver roi: " << ToString(receiverRoi); if (numUDPInterfaces == 2 && detType != slsDetectorDefs::GOTTHARD2) { - LOG(logINFO) << "port rois: " << sls::ToString(portRois); + LOG(logINFO) << "port rois: " << ToString(portRois); } } void Implementation::setReceiverROIMetadata(const ROI arg) { receiverRoiMetadata = arg; - LOG(logINFO) << "receiver roi Metadata: " << sls::ToString(receiverRoiMetadata); + LOG(logINFO) << "receiver roi Metadata: " << ToString(receiverRoiMetadata); } /************************************************** @@ -472,20 +474,20 @@ void Implementation::setFileFormat(const fileFormat f) { fileFormatType = BINARY; break; default: - throw sls::RuntimeError("Unknown file format"); + throw RuntimeError("Unknown file format"); } for (const auto &it : dataProcessor) it->SetupFileWriter(fileWriteEnable, fileFormatType, &hdf5LibMutex); } - LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType); + LOG(logINFO) << "File Format: " << ToString(fileFormatType); } std::string Implementation::getFilePath() const { return filePath; } void Implementation::setFilePath(const std::string &c) { if (!c.empty()) { - sls::mkdir_p(c); // throws if it can't create + mkdir_p(c); // throws if it can't create filePath = c; } LOG(logINFO) << "File path: " << filePath; @@ -615,7 +617,7 @@ std::vector Implementation::getNumMissingPackets() const { void Implementation::setScan(slsDetectorDefs::scanParameters s) { scanParams = s; - LOG(logINFO) << "Scan parameters: " << sls::ToString(scanParams); + LOG(logINFO) << "Scan parameters: " << ToString(scanParams); } void Implementation::startReceiver() { @@ -634,7 +636,7 @@ void Implementation::startReceiver() { startAcquisitionCallBack(filePath, fileName, fileIndex, imageSize, pStartAcquisition); } catch (const std::exception &e) { - throw sls::RuntimeError("Start Acquisition Callback Error: " + + throw RuntimeError("Start Acquisition Callback Error: " + std::string(e.what())); } if (rawDataReadyCallBack != nullptr) { @@ -657,7 +659,7 @@ void Implementation::startReceiver() { StartRunning(); LOG(logINFO) << "Receiver Started"; - LOG(logINFO) << "Status: " << sls::ToString(status); + LOG(logINFO) << "Status: " << ToString(status); } void Implementation::setStoppedFlag(bool stopped) { stoppedFlag = stopped; } @@ -698,7 +700,7 @@ void Implementation::stopReceiver() { } status = RUN_FINISHED; - LOG(logINFO) << "Status: " << sls::ToString(status); + LOG(logINFO) << "Status: " << ToString(status); { // statistics auto mp = getNumMissingPackets(); @@ -741,8 +743,8 @@ void Implementation::stopReceiver() { // change status status = IDLE; LOG(logINFO) << "Receiver Stopped"; - LOG(logINFO) << "Status: " << sls::ToString(status); - throw sls::RuntimeError( + LOG(logINFO) << "Status: " << ToString(status); + throw RuntimeError( "Acquisition Finished Callback Error: " + std::string(e.what())); } @@ -752,7 +754,7 @@ void Implementation::stopReceiver() { // change status status = IDLE; LOG(logINFO) << "Receiver Stopped"; - LOG(logINFO) << "Status: " << sls::ToString(status); + LOG(logINFO) << "Status: " << ToString(status); } void Implementation::startReadout() { @@ -823,9 +825,9 @@ void Implementation::CreateUDPSockets() { for (unsigned int i = 0; i < listener.size(); ++i) { listener[i]->CreateUDPSockets(); } - } catch (const sls::RuntimeError &e) { + } catch (const RuntimeError &e) { shutDownUDPSockets(); - throw sls::RuntimeError("Could not create UDP Socket(s)."); + throw RuntimeError("Could not create UDP Socket(s)."); } LOG(logDEBUG) << "UDP socket(s) created successfully."; } @@ -838,11 +840,11 @@ void Implementation::SetupWriter() { modulePos, numUDPInterfaces, udpPortNum[i], framesPerFile, numberOfTotalFrames, dynamicRange, detectorDataStream[i]); } - } catch (const sls::RuntimeError &e) { + } catch (const RuntimeError &e) { shutDownUDPSockets(); for (const auto &it : dataProcessor) it->CloseFiles(); - throw sls::RuntimeError("Could not create first data file."); + throw RuntimeError("Could not create first data file."); } } @@ -968,7 +970,7 @@ int Implementation::getNumberofUDPInterfaces() const { // not Eiger void Implementation::setNumberofUDPInterfaces(const int n) { if (detType == EIGER) { - throw sls::RuntimeError( + throw RuntimeError( "Cannot set number of UDP interfaces for Eiger"); } @@ -994,7 +996,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { // listener and dataprocessor threads try { auto fifo_ptr = fifo[i].get(); - listener.push_back(sls::make_unique( + listener.push_back(make_unique( i, detType, fifo_ptr, &status, &udpPortNum[i], ð[i], &udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode, &detectorDataStream[i], @@ -1007,7 +1009,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { ctbAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes(); } - dataProcessor.push_back(sls::make_unique( + dataProcessor.push_back(make_unique( i, detType, fifo_ptr, &dataStreamEnable, &streamingFrequency, &streamingTimerInMs, &streamingStartFnum, &framePadding, &ctbDbitList, @@ -1018,7 +1020,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { } catch (...) { listener.clear(); dataProcessor.clear(); - throw sls::RuntimeError( + throw RuntimeError( "Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")"); } @@ -1029,7 +1031,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { if (quadEnable) { flip = (i == 1 ? true : false); } - dataStreamer.push_back(sls::make_unique( + dataStreamer.push_back(make_unique( i, fifo[i].get(), &dynamicRange, &detectorRoi, &fileIndex, flip, numPorts, &quadEnable, &numberOfTotalFrames)); @@ -1044,7 +1046,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) { dataStreamer.clear(); dataStreamEnable = false; } - throw sls::RuntimeError( + throw RuntimeError( "Could not create datastreamer threads (index:" + std::to_string(i) + ")"); } @@ -1116,7 +1118,7 @@ void Implementation::setUDPSocketBufferSize(const int s) { size_t listSize = listener.size(); if ((detType == JUNGFRAU || detType == GOTTHARD2) && (int)listSize != numUDPInterfaces) { - throw sls::RuntimeError( + throw RuntimeError( "Number of Interfaces " + std::to_string(numUDPInterfaces) + " do not match listener size " + std::to_string(listSize)); } @@ -1126,7 +1128,7 @@ void Implementation::setUDPSocketBufferSize(const int s) { } // custom and didnt set, throw error if (s != 0 && udpSocketBufferSize != s) { - throw sls::RuntimeError("Could not set udp socket buffer size. (No " + throw RuntimeError("Could not set udp socket buffer size. (No " "CAP_NET_ADMIN privileges?)"); } } @@ -1156,7 +1158,7 @@ void Implementation::setDataStreamEnable(const bool enable) { if (quadEnable) { flip = (i == 1 ? true : false); } - dataStreamer.push_back(sls::make_unique( + dataStreamer.push_back(make_unique( i, fifo[i].get(), &dynamicRange, &detectorRoi, &fileIndex, flip, numPorts, &quadEnable, &numberOfTotalFrames)); @@ -1169,7 +1171,7 @@ void Implementation::setDataStreamEnable(const bool enable) { } catch (...) { dataStreamer.clear(); dataStreamEnable = false; - throw sls::RuntimeError( + throw RuntimeError( "Could not set data stream enable."); } } @@ -1213,11 +1215,11 @@ void Implementation::setStreamingPort(const uint32_t i) { LOG(logINFO) << "Streaming Port: " << streamingPort; } -sls::IpAddr Implementation::getStreamingSourceIP() const { +IpAddr Implementation::getStreamingSourceIP() const { return streamingSrcIP; } -void Implementation::setStreamingSourceIP(const sls::IpAddr ip) { +void Implementation::setStreamingSourceIP(const IpAddr ip) { streamingSrcIP = ip; LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP; } @@ -1243,7 +1245,7 @@ void Implementation::setAdditionalJsonHeader( it->SetAdditionalJsonHeader(c); } LOG(logINFO) << "Additional JSON Header: " - << sls::ToString(additionalJsonHeader); + << ToString(additionalJsonHeader); } std::string @@ -1251,7 +1253,7 @@ Implementation::getAdditionalJsonParameter(const std::string &key) const { if (additionalJsonHeader.find(key) != additionalJsonHeader.end()) { return additionalJsonHeader.at(key); } - throw sls::RuntimeError("No key " + key + + throw RuntimeError("No key " + key + " found in additional json header"); } @@ -1286,7 +1288,7 @@ void Implementation::setAdditionalJsonParameter(const std::string &key, it->SetAdditionalJsonHeader(additionalJsonHeader); } LOG(logINFO) << "Additional JSON Header: " - << sls::ToString(additionalJsonHeader); + << ToString(additionalJsonHeader); } /************************************************** @@ -1322,7 +1324,7 @@ void Implementation::updateTotalNumberOfFrames() { numberOfTotalFrames = numFrames * repeats * (int64_t)(numberOfAdditionalStorageCells + 1); if (numberOfTotalFrames == 0) { - throw sls::RuntimeError("Invalid total number of frames to receive: 0"); + throw RuntimeError("Invalid total number of frames to receive: 0"); } LOG(logINFO) << "Total Number of Frames: " << numberOfTotalFrames; } @@ -1393,7 +1395,7 @@ ns Implementation::getAcquisitionPeriod() const { return acquisitionPeriod; } void Implementation::setAcquisitionPeriod(const ns i) { acquisitionPeriod = i; - LOG(logINFO) << "Acquisition Period: " << sls::ToString(acquisitionPeriod); + LOG(logINFO) << "Acquisition Period: " << ToString(acquisitionPeriod); } ns Implementation::getAcquisitionTime() const { return acquisitionTime; } @@ -1409,54 +1411,54 @@ void Implementation::updateAcquisitionTime() { void Implementation::setAcquisitionTime(const ns i) { acquisitionTime = i; - LOG(logINFO) << "Acquisition Time: " << sls::ToString(acquisitionTime); + LOG(logINFO) << "Acquisition Time: " << ToString(acquisitionTime); } void Implementation::setAcquisitionTime1(const ns i) { acquisitionTime1 = i; - LOG(logINFO) << "Acquisition Time1: " << sls::ToString(acquisitionTime1); + LOG(logINFO) << "Acquisition Time1: " << ToString(acquisitionTime1); updateAcquisitionTime(); } void Implementation::setAcquisitionTime2(const ns i) { acquisitionTime2 = i; - LOG(logINFO) << "Acquisition Time2: " << sls::ToString(acquisitionTime2); + LOG(logINFO) << "Acquisition Time2: " << ToString(acquisitionTime2); updateAcquisitionTime(); } void Implementation::setAcquisitionTime3(const ns i) { acquisitionTime3 = i; - LOG(logINFO) << "Acquisition Time3: " << sls::ToString(acquisitionTime3); + LOG(logINFO) << "Acquisition Time3: " << ToString(acquisitionTime3); updateAcquisitionTime(); } void Implementation::setGateDelay1(const ns i) { gateDelay1 = i; - LOG(logINFO) << "Gate Delay1: " << sls::ToString(gateDelay1); + LOG(logINFO) << "Gate Delay1: " << ToString(gateDelay1); } void Implementation::setGateDelay2(const ns i) { gateDelay2 = i; - LOG(logINFO) << "Gate Delay2: " << sls::ToString(gateDelay2); + LOG(logINFO) << "Gate Delay2: " << ToString(gateDelay2); } void Implementation::setGateDelay3(const ns i) { gateDelay3 = i; - LOG(logINFO) << "Gate Delay3: " << sls::ToString(gateDelay3); + LOG(logINFO) << "Gate Delay3: " << ToString(gateDelay3); } ns Implementation::getSubExpTime() const { return subExpTime; } void Implementation::setSubExpTime(const ns i) { subExpTime = i; - LOG(logINFO) << "Sub Exposure Time: " << sls::ToString(subExpTime); + LOG(logINFO) << "Sub Exposure Time: " << ToString(subExpTime); } ns Implementation::getSubPeriod() const { return subPeriod; } void Implementation::setSubPeriod(const ns i) { subPeriod = i; - LOG(logINFO) << "Sub Period: " << sls::ToString(subPeriod); + LOG(logINFO) << "Sub Period: " << ToString(subPeriod); } uint32_t Implementation::getNumberofAnalogSamples() const { @@ -1497,7 +1499,7 @@ void Implementation::setCounterMask(const uint32_t i) { counterMask = i; SetupFifoStructure(); } - LOG(logINFO) << "Counter mask: " << sls::ToStringHex(counterMask); + LOG(logINFO) << "Counter mask: " << ToStringHex(counterMask); int ncounters = __builtin_popcount(counterMask); LOG(logINFO) << "Number of counters: " << ncounters; } @@ -1530,7 +1532,7 @@ void Implementation::setDetectorROI(slsDetectorDefs::ROI arg) { SetupFifoStructure(); } - LOG(logINFO) << "Detector ROI: " << sls::ToString(detectorRoi); + LOG(logINFO) << "Detector ROI: " << ToString(detectorRoi); LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); } @@ -1553,9 +1555,9 @@ void Implementation::setTenGigaEnable(const bool b) { detectorDataStream[RIGHT] = detectorDataStream10GbE[RIGHT]; } LOG(logDEBUG) << "Detector datastream updated [Left: " - << sls::ToString(detectorDataStream[LEFT]) + << ToString(detectorDataStream[LEFT]) << ", Right: " - << sls::ToString(detectorDataStream[RIGHT]) << "]"; + << ToString(detectorDataStream[RIGHT]) << "]"; } } LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled"); @@ -1623,14 +1625,14 @@ void Implementation::setDetectorDataStream(const portPosition port, const bool enable) { int index = (port == LEFT ? 0 : 1); detectorDataStream10GbE[index] = enable; - LOG(logINFO) << "Detector 10GbE datastream (" << sls::ToString(port) - << " Port): " << sls::ToString(detectorDataStream10GbE[index]); + LOG(logINFO) << "Detector 10GbE datastream (" << ToString(port) + << " Port): " << ToString(detectorDataStream10GbE[index]); // update datastream for 10g if (tengigaEnable) { detectorDataStream[index] = detectorDataStream10GbE[index]; LOG(logDEBUG) << "Detector datastream updated [" << (index == 0 ? "Left" : "Right") - << "] : " << sls::ToString(detectorDataStream[index]); + << "] : " << ToString(detectorDataStream[index]); } } @@ -1649,12 +1651,12 @@ void Implementation::setThresholdEnergy(const int value) { void Implementation::setThresholdEnergy(const std::array value) { thresholdAllEnergyeV = value; LOG(logINFO) << "Threshold Energy (eV): " - << sls::ToString(thresholdAllEnergyeV); + << ToString(thresholdAllEnergyeV); } void Implementation::setRateCorrections(const std::vector &t) { rateCorrections = t; - LOG(logINFO) << "Rate Corrections: " << sls::ToString(rateCorrections); + LOG(logINFO) << "Rate Corrections: " << ToString(rateCorrections); } slsDetectorDefs::readoutMode Implementation::getReadoutMode() const { @@ -1668,7 +1670,7 @@ void Implementation::setReadoutMode(const readoutMode f) { generalData->SetReadoutMode(f); SetupFifoStructure(); } - LOG(logINFO) << "Readout Mode: " << sls::ToString(f); + LOG(logINFO) << "Readout Mode: " << ToString(f); LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); } @@ -1748,3 +1750,5 @@ void Implementation::registerCallBackRawDataModifyReady( it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack, pRawDataReady); } + +} // namespace sls diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index a084de566..605b47cd5 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -6,12 +6,7 @@ #include "sls/container_utils.h" #include "sls/logger.h" #include "sls/network_utils.h" -class GeneralData; -class Listener; -class DataProcessor; -class DataStreamer; -class Fifo; -class slsDetectorDefs; +#include "sls/sls_detector_defs.h" #include #include @@ -20,8 +15,16 @@ class slsDetectorDefs; #include #include #include + +namespace sls { using ns = std::chrono::nanoseconds; +class GeneralData; +class Listener; +class DataProcessor; +class DataStreamer; +class Fifo; + class Implementation : private virtual slsDetectorDefs { public: explicit Implementation(const detectorType d); @@ -137,8 +140,8 @@ class Implementation : private virtual slsDetectorDefs { void setStreamingStartingFrameNumber(const uint32_t fnum); uint32_t getStreamingPort() const; void setStreamingPort(const uint32_t i); - sls::IpAddr getStreamingSourceIP() const; - void setStreamingSourceIP(const sls::IpAddr ip); + IpAddr getStreamingSourceIP() const; + void setStreamingSourceIP(const IpAddr ip); int getStreamingHwm() const; void setStreamingHwm(const int i); std::map getAdditionalJsonHeader() const; @@ -338,7 +341,7 @@ class Implementation : private virtual slsDetectorDefs { uint32_t streamingTimerInMs{DEFAULT_STREAMING_TIMER_IN_MS}; uint32_t streamingStartFnum{0}; uint32_t streamingPort{0}; - sls::IpAddr streamingSrcIP = sls::IpAddr{}; + IpAddr streamingSrcIP = IpAddr{}; int streamingHwm{-1}; std::map additionalJsonHeader; @@ -406,3 +409,5 @@ class Implementation : private virtual slsDetectorDefs { // mutex shared across all hdf5 virtual, master and data files std::mutex hdf5LibMutex; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index ea335ac8d..2638a2444 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -11,7 +11,7 @@ #include "Fifo.h" #include "GeneralData.h" #include "sls/UdpRxSocket.h" -#include "sls/container_utils.h" // For sls::make_unique<> +#include "sls/container_utils.h" // For make_unique<> #include "sls/network_utils.h" #include "sls/sls_detector_exceptions.h" @@ -19,6 +19,8 @@ #include #include +namespace sls { + const std::string Listener::TypeName = "Listener"; Listener::Listener(int ind, detectorType dtype, Fifo *f, @@ -86,9 +88,9 @@ void Listener::ResetParametersforNewAcquisition() { if (myDetectorType == GOTTHARD2 && index != 0) { packetSize = generalData->vetoPacketSize; } - carryOverPacket = sls::make_unique(packetSize); + carryOverPacket = make_unique(packetSize); memset(carryOverPacket.get(), 0, packetSize); - listeningPacket = sls::make_unique(packetSize); + listeningPacket = make_unique(packetSize); memset(carryOverPacket.get(), 0, packetSize); numPacketsStatistic = 0; @@ -139,14 +141,14 @@ void Listener::CreateUDPSockets() { // InterfaceNameToIp(eth).str().c_str() try { - udpSocket = sls::make_unique( + udpSocket = make_unique( *udpPortNumber, packetSize, - ((*eth).length() ? sls::InterfaceNameToIp(*eth).str().c_str() + ((*eth).length() ? InterfaceNameToIp(*eth).str().c_str() : nullptr), *udpSocketBufferSize); LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber; } catch (...) { - throw sls::RuntimeError("Could not create UDP socket on port " + + throw RuntimeError("Could not create UDP socket on port " + std::to_string(*udpPortNumber)); } @@ -188,9 +190,9 @@ void Listener::CreateDummySocketForUDPSocketBufferSize(int s) { // create dummy socket try { - sls::UdpRxSocket g(*udpPortNumber, packetSize, + UdpRxSocket g(*udpPortNumber, packetSize, ((*eth).length() - ? sls::InterfaceNameToIp(*eth).str().c_str() + ? InterfaceNameToIp(*eth).str().c_str() : nullptr), *udpSocketBufferSize); @@ -204,7 +206,7 @@ void Listener::CreateDummySocketForUDPSocketBufferSize(int s) { } } catch (...) { - throw sls::RuntimeError("Could not create a test UDP socket on port " + + throw RuntimeError("Could not create a test UDP socket on port " + std::to_string(*udpPortNumber)); } } @@ -649,3 +651,5 @@ void Listener::PrintFifoStatistics() { << " \tFree_Slots_Min_Level:" << fifo->GetMinLevelForFifoFree() << " \tCurrent_Frame#:" << currentFrameIndex; } + +} // namespace sls diff --git a/slsReceiverSoftware/src/Listener.h b/slsReceiverSoftware/src/Listener.h index 89d67d085..ffb3cf1b3 100644 --- a/slsReceiverSoftware/src/Listener.h +++ b/slsReceiverSoftware/src/Listener.h @@ -16,6 +16,8 @@ #include #include +namespace sls { + class GeneralData; class Fifo; @@ -117,7 +119,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { // individual members detectorType myDetectorType; std::atomic *status; - std::unique_ptr udpSocket{nullptr}; + std::unique_ptr udpSocket{nullptr}; uint32_t *udpPortNumber; std::string *eth; int *udpSocketBufferSize; @@ -172,3 +174,5 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { * (pecific to gotthard, can vary between modules, hence defined here) */ bool oddStartingPacket{true}; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index 1086d5988..8de7e2f9c 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -2,6 +2,8 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #include "MasterAttributes.h" +namespace sls { + void MasterAttributes::GetBinaryAttributes( rapidjson::PrettyWriter *w) { w->StartObject(); @@ -29,7 +31,7 @@ void MasterAttributes::GetBinaryAttributes( GetCtbBinaryAttributes(w); break; default: - throw sls::RuntimeError( + throw RuntimeError( "Unknown Detector type to get master attributes"); } GetFinalBinaryAttributes(w); @@ -62,7 +64,7 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { WriteCtbHDF5Attributes(fd, group); break; default: - throw sls::RuntimeError( + throw RuntimeError( "Unknown Detector type to get master attributes"); } WriteFinalHDF5Attributes(fd, group); @@ -75,14 +77,14 @@ void MasterAttributes::GetCommonBinaryAttributes( w->SetMaxDecimalPlaces(2); w->Double(BINARY_WRITER_VERSION); w->Key("Timestamp"); - time_t t = time(nullptr); + time_t t = std::time(nullptr); std::string sTime(ctime(&t)); std::replace(sTime.begin(), sTime.end(), '\n', '\0'); w->String(sTime.c_str()); w->Key("Detector Type"); - w->String(sls::ToString(detType).c_str()); + w->String(ToString(detType).c_str()); w->Key("Timing Mode"); - w->String(sls::ToString(timingMode).c_str()); + w->String(ToString(timingMode).c_str()); w->Key("Geometry"); w->StartObject(); w->Key("x"); @@ -102,11 +104,11 @@ void MasterAttributes::GetCommonBinaryAttributes( w->Key("Max Frames Per File"); w->Uint(maxFramesPerFile); w->Key("Frame Discard Policy"); - w->String(sls::ToString(frameDiscardMode).c_str()); + w->String(ToString(frameDiscardMode).c_str()); w->Key("Frame Padding"); w->Uint(framePadding); w->Key("Scan Parameters"); - w->String(sls::ToString(scanParams).c_str()); + w->String(ToString(scanParams).c_str()); w->Key("Total Frames"); w->Uint64(totalFrames); w->Key("Receiver Roi"); @@ -127,7 +129,7 @@ void MasterAttributes::GetFinalBinaryAttributes( // adding few common parameters to the end if (!additionalJsonHeader.empty()) { w->Key("Additional Json Header"); - w->String(sls::ToString(additionalJsonHeader).c_str()); + w->String(ToString(additionalJsonHeader).c_str()); } w->Key("Frames in File"); w->Uint64(framesInFile); @@ -182,7 +184,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { DataSpace dataspace = DataSpace(H5S_SCALAR); DataSet dataset = group->createDataSet("Timestamp", strdatatype, dataspace); - sls::strcpy_safe(c, std::string(ctime(&t))); + strcpy_safe(c, std::string(ctime(&t))); dataset.write(c, strdatatype); } // detector type @@ -191,7 +193,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Detector Type", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(detType)); + strcpy_safe(c, ToString(detType)); dataset.write(c, strdatatype); } // timing mode @@ -200,7 +202,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Timing Mode", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(timingMode)); + strcpy_safe(c, ToString(timingMode)); dataset.write(c, strdatatype); } // TODO: make this into an array? @@ -228,7 +230,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); Attribute attribute = dataset.createAttribute("Unit", strdatatype, dataspaceAttr); - sls::strcpy_safe(c, "bytes"); + strcpy_safe(c, "bytes"); attribute.write(strdatatype, c); } // TODO: make this into an array? @@ -259,7 +261,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Frame Discard Policy", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(frameDiscardMode)); + strcpy_safe(c, ToString(frameDiscardMode)); dataset.write(c, strdatatype); } // Frame Padding @@ -275,7 +277,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Scan Parameters", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(scanParams)); + strcpy_safe(c, ToString(scanParams)); dataset.write(c, strdatatype); } // Total Frames @@ -326,12 +328,12 @@ void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { } // additional json header if (!additionalJsonHeader.empty()) { - std::string json = sls::ToString(additionalJsonHeader); + std::string json = ToString(additionalJsonHeader); StrType strdatatype(PredType::C_S1, json.length()); DataSpace dataspace = DataSpace(H5S_SCALAR); DataSet dataset = group->createDataSet("Additional JSON Header", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(additionalJsonHeader)); + strcpy_safe(c, ToString(additionalJsonHeader)); dataset.write(c, strdatatype); } } @@ -342,7 +344,7 @@ void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { DataSet dataset = group->createDataSet("Exposure Time", strdatatype, dataspace); char c[1024]{}; - sls::strcpy_safe(c, sls::ToString(exptime)); + strcpy_safe(c, ToString(exptime)); dataset.write(c, strdatatype); } @@ -352,7 +354,7 @@ void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { DataSet dataset = group->createDataSet("Acquisition Period", strdatatype, dataspace); char c[1024]{}; - sls::strcpy_safe(c, sls::ToString(period)); + strcpy_safe(c, ToString(period)); dataset.write(c, strdatatype); } @@ -417,7 +419,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); Attribute attribute = dataset.createAttribute("Unit", strdatatype, dataspaceAttr); - sls::strcpy_safe(c, "eV"); + strcpy_safe(c, "eV"); attribute.write(strdatatype, c); } @@ -427,7 +429,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 1024); DataSet dataset = group->createDataSet("Threshold Energies", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV)); + strcpy_safe(c, ToString(thresholdAllEnergyeV)); dataset.write(c, strdatatype); } @@ -437,7 +439,7 @@ void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Sub Exposure Time", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(subExptime)); + strcpy_safe(c, ToString(subExptime)); dataset.write(c, strdatatype); } @@ -447,7 +449,7 @@ void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Sub Period", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(subPeriod)); + strcpy_safe(c, ToString(subPeriod)); dataset.write(c, strdatatype); } @@ -464,7 +466,7 @@ void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 1024); DataSet dataset = group->createDataSet("Rate Corrections", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(ratecorr)); + strcpy_safe(c, ToString(ratecorr)); dataset.write(c, strdatatype); } @@ -482,7 +484,7 @@ void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Exposure Time1", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(exptimeArray[i])); + strcpy_safe(c, ToString(exptimeArray[i])); dataset.write(c, strdatatype); } } @@ -494,7 +496,7 @@ void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Gate Delay1", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(gateDelayArray[i])); + strcpy_safe(c, ToString(gateDelayArray[i])); dataset.write(c, strdatatype); } } @@ -512,7 +514,7 @@ void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) { DataSet dataset = group->createDataSet("Burst Mode", strdatatype, dataspace); char c[1024]{}; - sls::strcpy_safe(c, sls::ToString(burstMode)); + strcpy_safe(c, ToString(burstMode)); dataset.write(c, strdatatype); } @@ -569,9 +571,9 @@ void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) { void MasterAttributes::GetGotthardBinaryAttributes( rapidjson::PrettyWriter *w) { w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Detector Roi"); w->StartObject(); w->Key("xmin"); @@ -592,9 +594,9 @@ void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::GetJungfrauBinaryAttributes( rapidjson::PrettyWriter *w) { w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Number of UDP Interfaces"); w->Uint(numUDPInterfaces); w->Key("Number of rows"); @@ -617,21 +619,21 @@ void MasterAttributes::GetEigerBinaryAttributes( w->Key("Ten Giga"); w->Uint(tenGiga); w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Threshold Energy"); w->Int(thresholdEnergyeV); w->Key("Sub Exptime"); - w->String(sls::ToString(subExptime).c_str()); + w->String(ToString(subExptime).c_str()); w->Key("Sub Period"); - w->String(sls::ToString(subPeriod).c_str()); + w->String(ToString(subPeriod).c_str()); w->Key("Quad"); w->Int(quad); w->Key("Number of rows"); w->Int(readNRows); w->Key("Rate Corrections"); - w->String(sls::ToString(ratecorr).c_str()); + w->String(ToString(ratecorr).c_str()); } #ifdef HDF5C @@ -656,21 +658,21 @@ void MasterAttributes::GetMythen3BinaryAttributes( w->Key("Ten Giga"); w->Uint(tenGiga); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Counter Mask"); - w->String(sls::ToStringHex(counterMask).c_str()); + w->String(ToStringHex(counterMask).c_str()); for (int i = 0; i != 3; ++i) { w->Key((std::string("Exptime") + std::to_string(i + 1)).c_str()); - w->String(sls::ToString(exptimeArray[i]).c_str()); + w->String(ToString(exptimeArray[i]).c_str()); } for (int i = 0; i != 3; ++i) { w->Key((std::string("GateDelay") + std::to_string(i + 1)).c_str()); - w->String(sls::ToString(gateDelayArray[i]).c_str()); + w->String(ToString(gateDelayArray[i]).c_str()); } w->Key("Gates"); w->Uint(gates); w->Key("Threshold Energies"); - w->String(sls::ToString(thresholdAllEnergyeV).c_str()); + w->String(ToString(thresholdAllEnergyeV).c_str()); } #ifdef HDF5C @@ -689,11 +691,11 @@ void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::GetGotthard2BinaryAttributes( rapidjson::PrettyWriter *w) { w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Burst Mode"); - w->String(sls::ToString(burstMode).c_str()); + w->String(ToString(burstMode).c_str()); } #ifdef HDF5C @@ -707,13 +709,13 @@ void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::GetMoenchBinaryAttributes( rapidjson::PrettyWriter *w) { w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Ten Giga"); w->Uint(tenGiga); w->Key("ADC Mask"); - w->String(sls::ToStringHex(adcmask).c_str()); + w->String(ToStringHex(adcmask).c_str()); w->Key("Analog Samples"); w->Uint(analogSamples); } @@ -731,13 +733,13 @@ void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::GetCtbBinaryAttributes( rapidjson::PrettyWriter *w) { w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); + w->String(ToString(exptime).c_str()); w->Key("Period"); - w->String(sls::ToString(period).c_str()); + w->String(ToString(period).c_str()); w->Key("Ten Giga"); w->Uint(tenGiga); w->Key("ADC Mask"); - w->String(sls::ToStringHex(adcmask).c_str()); + w->String(ToStringHex(adcmask).c_str()); w->Key("Analog Flag"); w->Uint(analog); w->Key("Analog Samples"); @@ -766,3 +768,5 @@ void MasterAttributes::WriteCtbHDF5Attributes(H5File *fd, Group *group) { MasterAttributes::WriteHDF5DbitList(fd, group); } #endif + +} // namespace sls diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index d45df4705..5fbb0a41a 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -9,6 +9,11 @@ #include #include +#include + +namespace sls { + +using ns = std::chrono::nanoseconds; #ifdef HDF5C #include "H5Cpp.h" @@ -17,9 +22,6 @@ using namespace H5; #endif #endif -#include -using ns = std::chrono::nanoseconds; - class MasterAttributes { public: // (before acquisition) @@ -148,3 +150,5 @@ class MasterAttributes { void WriteCtbHDF5Attributes(H5File *fd, Group *group); #endif }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/MasterFileUtility.cpp b/slsReceiverSoftware/src/MasterFileUtility.cpp index 506ba7b83..22ba0400d 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.cpp +++ b/slsReceiverSoftware/src/MasterFileUtility.cpp @@ -5,6 +5,8 @@ #include +namespace sls { + namespace masterFileUtility { std::string CreateMasterBinaryFile(const std::string &filePath, @@ -23,7 +25,7 @@ std::string CreateMasterBinaryFile(const std::string &filePath, mode = "wx"; FILE *fd = fopen(fileName.c_str(), mode.c_str()); if(!fd) { - throw sls::RuntimeError("Could not create/overwrite binary master file " + + throw RuntimeError("Could not create/overwrite binary master file " + fileName); } @@ -32,7 +34,7 @@ std::string CreateMasterBinaryFile(const std::string &filePath, attr->GetBinaryAttributes(&writer); if (fwrite(s.GetString(), 1, strlen(s.GetString()), fd) != strlen(s.GetString())) { - throw sls::RuntimeError( + throw RuntimeError( "Master binary file incorrect number of bytes written to file"); } if (fd) { @@ -64,7 +66,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, FileCreatPropList::DEFAULT, flist); // open data file - fd = sls::make_unique(dataFilename.c_str(), H5F_ACC_RDONLY, + fd = make_unique(dataFilename.c_str(), H5F_ACC_RDONLY, FileCreatPropList::DEFAULT, flist); // create link for data dataset @@ -73,7 +75,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, if (H5Lcreate_external(dataFilename.c_str(), dataSetname.c_str(), masterfd.getLocId(), linkname.c_str(), H5P_DEFAULT, H5P_DEFAULT) < 0) { - throw sls::RuntimeError( + throw RuntimeError( "Could not create link to data dataset in master"); } @@ -85,7 +87,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, parameterNames[i].c_str(), masterfd.getLocId(), linkname.c_str(), H5P_DEFAULT, H5P_DEFAULT) < 0) { - throw sls::RuntimeError( + throw RuntimeError( "Could not create link to parameter dataset in master"); } } @@ -95,7 +97,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, error.printErrorStack(); if (fd != nullptr) fd->close(); - throw sls::RuntimeError("Could not link in master hdf5 file"); + throw RuntimeError("Could not link in master hdf5 file"); } if (!silentMode) { LOG(logINFO) << "Linked in Master File: " << dataFilename; @@ -127,7 +129,7 @@ std::string CreateMasterHDF5File(const std::string &filePath, if (overWriteEnable) { createFlags = H5F_ACC_TRUNC; } - fd = sls::make_unique(fileName.c_str(), createFlags, + fd = make_unique(fileName.c_str(), createFlags, FileCreatPropList::DEFAULT, flist); // attributes - version @@ -151,7 +153,7 @@ std::string CreateMasterHDF5File(const std::string &filePath, error.printErrorStack(); if (fd != nullptr) fd->close(); - throw sls::RuntimeError( + throw RuntimeError( "Could not create/overwrite master HDF5 handles"); } if (!silentMode) { @@ -195,10 +197,10 @@ std::array CreateVirtualHDF5File( FileAccPropList fapl; fapl.setFcloseDegree(H5F_CLOSE_STRONG); if (!overWriteEnable) - fd = sls::make_unique(fileName.c_str(), H5F_ACC_EXCL, + fd = make_unique(fileName.c_str(), H5F_ACC_EXCL, FileCreatPropList::DEFAULT, fapl); else - fd = sls::make_unique(fileName.c_str(), H5F_ACC_TRUNC, + fd = make_unique(fileName.c_str(), H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); // attributes - version @@ -338,7 +340,7 @@ std::array CreateVirtualHDF5File( if (fd) { fd->close(); } - throw sls::RuntimeError( + throw RuntimeError( "Could not create/overwrite virtual HDF5 handles"); } if (!silentMode) { @@ -349,3 +351,5 @@ std::array CreateVirtualHDF5File( #endif } // namespace masterFileUtility + +} // namespace sls diff --git a/slsReceiverSoftware/src/MasterFileUtility.h b/slsReceiverSoftware/src/MasterFileUtility.h index ed90cc52e..4a4b0e136 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.h +++ b/slsReceiverSoftware/src/MasterFileUtility.h @@ -4,6 +4,10 @@ #include "MasterAttributes.h" +namespace sls { + +namespace masterFileUtility { + #ifdef HDF5C #include "H5Cpp.h" #include @@ -12,7 +16,6 @@ using namespace H5; #endif #endif -namespace masterFileUtility { std::string CreateMasterBinaryFile(const std::string &filePath, const std::string &fileNamePrefix, @@ -47,4 +50,6 @@ std::array CreateVirtualHDF5File( const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, bool gotthard25um); #endif -} // namespace masterFileUtility \ No newline at end of file +} // namespace masterFileUtility + +} // namespace sls diff --git a/slsReceiverSoftware/src/MultiReceiverApp.cpp b/slsReceiverSoftware/src/MultiReceiverApp.cpp index a02656478..93605f6f7 100644 --- a/slsReceiverSoftware/src/MultiReceiverApp.cpp +++ b/slsReceiverSoftware/src/MultiReceiverApp.cpp @@ -53,7 +53,7 @@ void printHelp() { */ int StartAcq(const std::string &filePath, const std::string &fileName, uint64_t fileIndex, size_t imageSize, void *objectPointer) { - LOG(logINFOBLUE) << "#### StartAcq: filePath:" << filePath + LOG(sls::logINFOBLUE) << "#### StartAcq: filePath:" << filePath << " fileName:" << fileName << " fileIndex:" << fileIndex << " imageSize:" << imageSize << " ####"; return 0; @@ -61,7 +61,7 @@ int StartAcq(const std::string &filePath, const std::string &fileName, /** Acquisition Finished Call back */ void AcquisitionFinished(uint64_t framesCaught, void *objectPointer) { - LOG(logINFOBLUE) << "#### AcquisitionFinished: framesCaught:" + LOG(sls::logINFOBLUE) << "#### AcquisitionFinished: framesCaught:" << framesCaught << " ####"; } @@ -204,7 +204,7 @@ int main(int argc, char *argv[]) { try { receiver = sls::make_unique(startTCPPort + i); } catch (...) { - LOG(logINFOBLUE) + LOG(sls::logINFOBLUE) << "Exiting Child Process [ Tid: " << gettid() << " ]"; throw; } diff --git a/slsReceiverSoftware/src/Receiver.cpp b/slsReceiverSoftware/src/Receiver.cpp index 79c1fa266..657137b11 100644 --- a/slsReceiverSoftware/src/Receiver.cpp +++ b/slsReceiverSoftware/src/Receiver.cpp @@ -16,14 +16,14 @@ #include #include +namespace sls { + // gettid added in glibc 2.30 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 #include #define gettid() syscall(SYS_gettid) #endif -namespace sls { - Receiver::~Receiver() = default; Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) { @@ -66,7 +66,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) { case 'u': if (sscanf(optarg, "%u", &userid) != 1) { - throw sls::RuntimeError("Could not scan uid"); + throw RuntimeError("Could not scan uid"); } break; @@ -90,7 +90,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) { "\t started with privileges. \n\n"; // std::cout << help_message << std::endl; - throw sls::RuntimeError(help_message); + throw RuntimeError(help_message); } } @@ -103,25 +103,25 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) { if (seteuid(userid) != 0) { std::ostringstream oss; oss << "Could not set Effective UID to " << userid; - throw sls::RuntimeError(oss.str()); + throw RuntimeError(oss.str()); } if (geteuid() != userid) { std::ostringstream oss; oss << "Could not set Effective UID to " << userid << ". Got " << geteuid(); - throw sls::RuntimeError(oss.str()); + throw RuntimeError(oss.str()); } LOG(logINFO) << "Process Effective UID changed to " << userid; } } // might throw an exception - tcpipInterface = sls::make_unique(tcpip_port_no); + tcpipInterface = make_unique(tcpip_port_no); } Receiver::Receiver(int tcpip_port_no) { // might throw an exception - tcpipInterface = sls::make_unique(tcpip_port_no); + tcpipInterface = make_unique(tcpip_port_no); } int64_t Receiver::getReceiverVersion() { diff --git a/slsReceiverSoftware/src/ReceiverApp.cpp b/slsReceiverSoftware/src/ReceiverApp.cpp index 9a9347e64..767339869 100644 --- a/slsReceiverSoftware/src/ReceiverApp.cpp +++ b/slsReceiverSoftware/src/ReceiverApp.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { sem_init(&semaphore, 1, 0); - LOG(logINFOBLUE) << "Created [ Tid: " << gettid() << " ]"; + LOG(sls::logINFOBLUE) << "Created [ Tid: " << gettid() << " ]"; // Catch signal SIGINT to close files and call destructors properly struct sigaction sa; @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { sigemptyset(&sa.sa_mask); // dont block additional signals during invocation // of handler if (sigaction(SIGINT, &sa, nullptr) == -1) { - LOG(logERROR) << "Could not set handler function for SIGINT"; + LOG(sls::logERROR) << "Could not set handler function for SIGINT"; } // if socket crash, ignores SISPIPE, prevents global signal handler @@ -44,18 +44,18 @@ int main(int argc, char *argv[]) { sigemptyset(&asa.sa_mask); // dont block additional signals during // invocation of handler if (sigaction(SIGPIPE, &asa, nullptr) == -1) { - LOG(logERROR) << "Could not set handler function for SIGPIPE"; + LOG(sls::logERROR) << "Could not set handler function for SIGPIPE"; } try { sls::Receiver r(argc, argv); - LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]"; + LOG(sls::logINFO) << "[ Press \'Ctrl+c\' to exit ]"; sem_wait(&semaphore); sem_destroy(&semaphore); } catch (...) { // pass } - LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]"; - LOG(logINFO) << "Exiting Receiver"; + LOG(sls::logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]"; + LOG(sls::logINFO) << "Exiting Receiver"; return 0; } diff --git a/slsReceiverSoftware/src/ThreadObject.cpp b/slsReceiverSoftware/src/ThreadObject.cpp index 1d3eb76a1..67b3fbda6 100644 --- a/slsReceiverSoftware/src/ThreadObject.cpp +++ b/slsReceiverSoftware/src/ThreadObject.cpp @@ -10,6 +10,8 @@ #include #include +namespace sls { + // gettid added in glibc 2.30 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 #include @@ -23,7 +25,7 @@ ThreadObject::ThreadObject(int threadIndex, std::string threadType) try { threadObject = std::thread(&ThreadObject::RunningThread, this); } catch (...) { - throw sls::RuntimeError("Could not create " + type + + throw RuntimeError("Could not create " + type + " thread with index " + std::to_string(index)); } } @@ -75,3 +77,5 @@ void ThreadObject::SetThreadPriority(int priority) { LOG(logINFO) << "Priorities set - " << type << ": " << priority; } } + +} // namespace sls diff --git a/slsReceiverSoftware/src/ThreadObject.h b/slsReceiverSoftware/src/ThreadObject.h index c708b960b..ffba674a5 100644 --- a/slsReceiverSoftware/src/ThreadObject.h +++ b/slsReceiverSoftware/src/ThreadObject.h @@ -17,6 +17,8 @@ #include #include +namespace sls { + class ThreadObject : private virtual slsDetectorDefs { protected: const int index{0}; @@ -47,3 +49,5 @@ class ThreadObject : private virtual slsDetectorDefs { const std::string type; std::atomic threadId{0}; }; + +} // namespace sls diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index 96c03c857..e65623e90 100644 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -5,6 +5,8 @@ #include "sls/sls_detector_defs.h" #include +namespace sls { + #define MAX_DIMENSIONS (2) #define MAX_NUMBER_OF_LISTENING_THREADS (2) @@ -55,3 +57,6 @@ #define PROCESSOR_PRIORITY (70) #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) + + +} // namespace sls diff --git a/slsSupportLib/include/sls/StaticVector.h b/slsSupportLib/include/sls/StaticVector.h index 22329fe6e..794bbee71 100644 --- a/slsSupportLib/include/sls/StaticVector.h +++ b/slsSupportLib/include/sls/StaticVector.h @@ -193,7 +193,7 @@ bool operator!=(const std::vector &lhs, template std::ostream &operator<<(std::ostream &os, - const sls::StaticVector &c) { + const StaticVector &c) { return os << ToString(c); } diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index 246ae5d65..bfeb09fd9 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -273,7 +273,7 @@ T StringTo(const std::string &t, const std::string &unit) { try { tval = std::stod(t); } catch (const std::invalid_argument &e) { - throw sls::RuntimeError("Could not convert string to time"); + throw RuntimeError("Could not convert string to time"); } using std::chrono::duration; @@ -287,7 +287,7 @@ T StringTo(const std::string &t, const std::string &unit) { } else if (unit == "s" || unit.empty()) { return duration_cast(std::chrono::duration(tval)); } else { - throw sls::RuntimeError( + throw RuntimeError( "Invalid unit in conversion from string to std::chrono::duration"); } } diff --git a/slsSupportLib/include/sls/ZmqSocket.h b/slsSupportLib/include/sls/ZmqSocket.h index 803a5bafe..e3f546afd 100644 --- a/slsSupportLib/include/sls/ZmqSocket.h +++ b/slsSupportLib/include/sls/ZmqSocket.h @@ -10,17 +10,20 @@ */ #include "sls/sls_detector_exceptions.h" +#include "sls/container_utils.h" + +#include +#include #include //json header in zmq stream +#include + +namespace sls { #define MAX_STR_LENGTH 1000 - // #define ZMQ_DETAIL #define ROIVERBOSITY -class zmq_msg_t; -#include "sls/container_utils.h" -#include -#include + /** zmq header structure */ struct zmqHeader { /** true if incoming data, false if end of acquisition */ @@ -222,5 +225,7 @@ class ZmqSocket { mySocketDescriptors sockfd; std::unique_ptr header_buffer = - sls::make_unique(MAX_STR_LENGTH); + make_unique(MAX_STR_LENGTH); }; + +} // namespace sls diff --git a/slsSupportLib/include/sls/logger.h b/slsSupportLib/include/sls/logger.h index 3331fc94c..437f7e905 100644 --- a/slsSupportLib/include/sls/logger.h +++ b/slsSupportLib/include/sls/logger.h @@ -8,6 +8,8 @@ #include #include +namespace sls { + enum TLogLevel { logERROR, logWARNING, @@ -25,7 +27,7 @@ enum TLogLevel { // Compiler should optimize away anything below this value #ifndef LOG_MAX_REPORTING_LEVEL -#define LOG_MAX_REPORTING_LEVEL logINFO +#define LOG_MAX_REPORTING_LEVEL sls::logINFO #endif #define __AT__ \ @@ -37,7 +39,6 @@ enum TLogLevel { std::string(__SHORT_FORM_OF_FILE__) + std::string("::") + \ std::string(__func__) + std::string("(): ") -namespace sls { class Logger { std::ostringstream os; TLogLevel level = LOG_MAX_REPORTING_LEVEL; diff --git a/slsSupportLib/src/ClientSocket.cpp b/slsSupportLib/src/ClientSocket.cpp index fdf41140f..866314372 100644 --- a/slsSupportLib/src/ClientSocket.cpp +++ b/slsSupportLib/src/ClientSocket.cpp @@ -93,7 +93,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { Receive(retval, retval_size); } // debugging - catch (sls::SocketError &e) { + catch (SocketError &e) { if (socketType == "Receiver") { throw ReceiverError("Receiver returned: " + std::string(e.what())); } else if (socketType == "Detector") { diff --git a/slsSupportLib/src/DataSocket.cpp b/slsSupportLib/src/DataSocket.cpp index 02f1c3cdb..25d016d0b 100644 --- a/slsSupportLib/src/DataSocket.cpp +++ b/slsSupportLib/src/DataSocket.cpp @@ -65,7 +65,7 @@ int DataSocket::Receive(void *buffer, size_t size) { ss << "TCP socket read " << bytes_read << " bytes instead of " << bytes_expected << " bytes (" << getFunctionNameFromEnum(static_cast(fnum_)) << ')'; - throw sls::SocketError(ss.str()); + throw SocketError(ss.str()); } } @@ -91,7 +91,7 @@ int DataSocket::Send(const void *buffer, size_t size) { ss << "TCP socket sent " << bytes_sent << " bytes instead of " << data_size << " bytes (" << getFunctionNameFromEnum(static_cast(fnum_)) << ')'; - throw sls::SocketError(ss.str()); + throw SocketError(ss.str()); } return bytes_sent; } diff --git a/slsSupportLib/src/ServerSocket.cpp b/slsSupportLib/src/ServerSocket.cpp index ed5c09bba..d8f235e2f 100644 --- a/slsSupportLib/src/ServerSocket.cpp +++ b/slsSupportLib/src/ServerSocket.cpp @@ -14,12 +14,14 @@ #include #include #include + + +namespace sls { + #define DEFAULT_PACKET_SIZE 1286 #define SOCKET_BUFFER_SIZE (100 * 1024 * 1024) // 100 MB #define DEFAULT_BACKLOG 5 -namespace sls { - ServerSocket::ServerSocket(int port) : DataSocket(socket(AF_INET, SOCK_STREAM, 0)), serverPort(port) { @@ -31,7 +33,7 @@ ServerSocket::ServerSocket(int port) if (bind(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) { close(); - throw sls::SocketError( + throw SocketError( std::string("Server ERROR: cannot bind socket with port number ") + std::to_string(port) + std::string(". Please check if another instance is running.")); @@ -49,7 +51,7 @@ ServerInterface ServerSocket::accept() { int newSocket = ::accept(getSocketId(), (struct sockaddr *)&clientAddr, &addr_size); if (newSocket == -1) { - throw sls::SocketError("Server ERROR: socket accept failed\n"); + throw SocketError("Server ERROR: socket accept failed\n"); } char tc[INET_ADDRSTRLEN]{}; inet_ntop(AF_INET, &(clientAddr.sin_addr), tc, INET_ADDRSTRLEN); diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 25d6b80f4..3b3cd072f 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -38,11 +38,11 @@ std::string ToString(const slsDetectorDefs::rxParameters &r) { << "hostname:" << r.hostname << std::endl << "udpInterfaces:" << r.udpInterfaces << std::endl << "udp_dstport:" << r.udp_dstport << std::endl - << "udp_dstip:" << sls::IpAddr(r.udp_dstip) << std::endl - << "udp_dstmac:" << sls::MacAddr(r.udp_dstmac) << std::endl + << "udp_dstip:" << IpAddr(r.udp_dstip) << std::endl + << "udp_dstmac:" << MacAddr(r.udp_dstmac) << std::endl << "udp_dstport2:" << r.udp_dstport2 << std::endl - << "udp_dstip2:" << sls::IpAddr(r.udp_dstip2) << std::endl - << "udp_dstmac2:" << sls::MacAddr(r.udp_dstmac2) << std::endl + << "udp_dstip2:" << IpAddr(r.udp_dstip2) << std::endl + << "udp_dstmac2:" << MacAddr(r.udp_dstmac2) << std::endl << "frames:" << r.frames << std::endl << "triggers:" << r.triggers << std::endl << "bursts:" << r.bursts << std::endl @@ -86,7 +86,7 @@ std::string ToString(const slsDetectorDefs::rxParameters &r) { << "gateDelay3:" << ToString(std::chrono::nanoseconds(r.gateDelay3Ns)) << std::endl << "gates:" << r.gates << std::endl - << "scanParams:" << sls::ToString(r.scanParams) << std::endl + << "scanParams:" << ToString(r.scanParams) << std::endl << ']'; return oss.str(); } @@ -123,7 +123,7 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::currentSrcParameters &r) { std::ostringstream oss; if (r.fix < -1 || r.fix > 1 || r.normal < -1 || r.normal > 1) { - throw sls::RuntimeError( + throw RuntimeError( "Invalid current source parameters. Cannot print."); } oss << '['; @@ -674,7 +674,7 @@ template <> defs::detectorType StringTo(const std::string &s) { return defs::MYTHEN3; if (s == "Gotthard2") return defs::GOTTHARD2; - throw sls::RuntimeError("Unknown detector type " + s); + throw RuntimeError("Unknown detector type " + s); } template <> defs::detectorSettings StringTo(const std::string &s) { @@ -718,7 +718,7 @@ template <> defs::detectorSettings StringTo(const std::string &s) { return defs::GAIN0; if (s == "g4_lg") return defs::G4_LOWGAIN; - throw sls::RuntimeError("Unknown setting " + s); + throw RuntimeError("Unknown setting " + s); } template <> defs::speedLevel StringTo(const std::string &s) { @@ -738,7 +738,7 @@ template <> defs::speedLevel StringTo(const std::string &s) { return defs::G2_108MHZ; if (s == "144") return defs::G2_144MHZ; - throw sls::RuntimeError("Unknown speed " + s); + throw RuntimeError("Unknown speed " + s); } template <> defs::timingMode StringTo(const std::string &s) { @@ -752,7 +752,7 @@ template <> defs::timingMode StringTo(const std::string &s) { return defs::BURST_TRIGGER; if (s == "trigger_gating") return defs::TRIGGER_GATED; - throw sls::RuntimeError("Unknown timing mode " + s); + throw RuntimeError("Unknown timing mode " + s); } template <> defs::frameDiscardPolicy StringTo(const std::string &s) { @@ -762,7 +762,7 @@ template <> defs::frameDiscardPolicy StringTo(const std::string &s) { return defs::DISCARD_EMPTY_FRAMES; if (s == "discardpartial") return defs::DISCARD_PARTIAL_FRAMES; - throw sls::RuntimeError("Unknown frame discard policy " + s); + throw RuntimeError("Unknown frame discard policy " + s); } template <> defs::fileFormat StringTo(const std::string &s) { @@ -770,7 +770,7 @@ template <> defs::fileFormat StringTo(const std::string &s) { return defs::HDF5; if (s == "binary") return defs::BINARY; - throw sls::RuntimeError("Unknown file format " + s); + throw RuntimeError("Unknown file format " + s); } template <> defs::externalSignalFlag StringTo(const std::string &s) { @@ -782,7 +782,7 @@ template <> defs::externalSignalFlag StringTo(const std::string &s) { return defs::INVERSION_ON; if (s == "inversion_off") return defs::INVERSION_OFF; - throw sls::RuntimeError("Unknown external signal flag " + s); + throw RuntimeError("Unknown external signal flag " + s); } template <> defs::readoutMode StringTo(const std::string &s) { @@ -792,7 +792,7 @@ template <> defs::readoutMode StringTo(const std::string &s) { return defs::DIGITAL_ONLY; if (s == "analog_digital") return defs::ANALOG_AND_DIGITAL; - throw sls::RuntimeError("Unknown readout mode " + s); + throw RuntimeError("Unknown readout mode " + s); } template <> defs::dacIndex StringTo(const std::string &s) { @@ -982,7 +982,7 @@ template <> defs::dacIndex StringTo(const std::string &s) { return defs::TEMPERATURE_FPGA3; if (s == "temp_slowadc") return defs::SLOW_ADC_TEMP; - throw sls::RuntimeError("Unknown dac Index " + s); + throw RuntimeError("Unknown dac Index " + s); } template <> defs::burstMode StringTo(const std::string &s) { @@ -994,7 +994,7 @@ template <> defs::burstMode StringTo(const std::string &s) { return defs::CONTINUOUS_INTERNAL; if (s == "cw_external") return defs::CONTINUOUS_EXTERNAL; - throw sls::RuntimeError("Unknown burst mode " + s); + throw RuntimeError("Unknown burst mode " + s); } template <> defs::timingSourceType StringTo(const std::string &s) { @@ -1002,7 +1002,7 @@ template <> defs::timingSourceType StringTo(const std::string &s) { return defs::TIMING_INTERNAL; if (s == "external") return defs::TIMING_EXTERNAL; - throw sls::RuntimeError("Unknown timing source type " + s); + throw RuntimeError("Unknown timing source type " + s); } template <> defs::M3_GainCaps StringTo(const std::string &s) { @@ -1018,7 +1018,7 @@ template <> defs::M3_GainCaps StringTo(const std::string &s) { return defs::M3_C225ACsh; if (s == "C15pre") return defs::M3_C15pre; - throw sls::RuntimeError("Unknown gain cap " + s); + throw RuntimeError("Unknown gain cap " + s); } template <> defs::portPosition StringTo(const std::string &s) { @@ -1030,7 +1030,7 @@ template <> defs::portPosition StringTo(const std::string &s) { return defs::TOP; if (s == "bottom") return defs::BOTTOM; - throw sls::RuntimeError("Unknown port position " + s); + throw RuntimeError("Unknown port position " + s); } template <> defs::streamingInterface StringTo(const std::string &s) { @@ -1043,7 +1043,7 @@ template <> defs::streamingInterface StringTo(const std::string &s) { return defs::streamingInterface::LOW_LATENCY_LINK; if (rs == "10gbe") return defs::streamingInterface::ETHERNET_10GB; - throw sls::RuntimeError("Unknown streamingInterface type " + s); + throw RuntimeError("Unknown streamingInterface type " + s); } template <> defs::vetoAlgorithm StringTo(const std::string &s) { @@ -1051,7 +1051,7 @@ template <> defs::vetoAlgorithm StringTo(const std::string &s) { return defs::ALG_HITS; if (s == "raw") return defs::ALG_RAW; - throw sls::RuntimeError("Unknown veto algorithm " + s); + throw RuntimeError("Unknown veto algorithm " + s); } template <> defs::gainMode StringTo(const std::string &s) { @@ -1067,7 +1067,7 @@ template <> defs::gainMode StringTo(const std::string &s) { return defs::FIX_G2; if (s == "fixg0") return defs::FIX_G0; - throw sls::RuntimeError("Unknown gain mode " + s); + throw RuntimeError("Unknown gain mode " + s); } template <> defs::polarity StringTo(const std::string &s) { @@ -1075,7 +1075,7 @@ template <> defs::polarity StringTo(const std::string &s) { return defs::POSITIVE; if (s == "neg") return defs::NEGATIVE; - throw sls::RuntimeError("Unknown polarity mode " + s); + throw RuntimeError("Unknown polarity mode " + s); } template <> uint32_t StringTo(const std::string &s) { @@ -1101,7 +1101,7 @@ template <> bool StringTo(const std::string &s) { case 1: return true; default: - throw sls::RuntimeError("Unknown boolean. Expecting be 0 or 1."); + throw RuntimeError("Unknown boolean. Expecting be 0 or 1."); } } diff --git a/slsSupportLib/src/ZmqSocket.cpp b/slsSupportLib/src/ZmqSocket.cpp index 61aa40f7c..4f9c7cf05 100644 --- a/slsSupportLib/src/ZmqSocket.cpp +++ b/slsSupportLib/src/ZmqSocket.cpp @@ -10,14 +10,15 @@ #include #include #include -#include + +namespace sls { using namespace rapidjson; ZmqSocket::ZmqSocket(const char *const hostname_or_ip, const uint32_t portnumber) : portno(portnumber), sockfd(false) { // Extra check that throws if conversion fails, could be removed - auto ipstr = sls::HostnameToIp(hostname_or_ip).str(); + auto ipstr = HostnameToIp(hostname_or_ip).str(); std::ostringstream oss; oss << "tcp://" << ipstr << ":" << portno; sockfd.serverAddress = oss.str(); @@ -26,20 +27,20 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip, // create context sockfd.contextDescriptor = zmq_ctx_new(); if (sockfd.contextDescriptor == nullptr) - throw sls::ZmqSocketError("Could not create contextDescriptor"); + throw ZmqSocketError("Could not create contextDescriptor"); // create subscriber sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_SUB); if (sockfd.socketDescriptor == nullptr) { PrintError(); - throw sls::ZmqSocketError("Could not create socket"); + throw ZmqSocketError("Could not create socket"); } // Socket Options provided above // an empty string implies receiving any messages if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SUBSCRIBE, "", 0)) { PrintError(); - throw sls::ZmqSocketError("Could set socket opt"); + throw ZmqSocketError("Could set socket opt"); } // ZMQ_LINGER default is already -1 means no messages discarded. use this // options if optimizing required ZMQ_SNDHWM default is 0 means no limit. @@ -48,7 +49,7 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip, if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_LINGER, &value, sizeof(value))) { PrintError(); - throw sls::ZmqSocketError("Could not set ZMQ_LINGER"); + throw ZmqSocketError("Could not set ZMQ_LINGER"); } LOG(logDEBUG) << "Default receive high water mark:" << GetReceiveHighWaterMark(); @@ -59,13 +60,13 @@ ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip) // create context sockfd.contextDescriptor = zmq_ctx_new(); if (sockfd.contextDescriptor == nullptr) - throw sls::ZmqSocketError("Could not create contextDescriptor"); + throw ZmqSocketError("Could not create contextDescriptor"); // create publisher sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_PUB); if (sockfd.socketDescriptor == nullptr) { PrintError(); - throw sls::ZmqSocketError("Could not create socket"); + throw ZmqSocketError("Could not create socket"); } LOG(logDEBUG) << "Default send high water mark:" << GetSendHighWaterMark(); @@ -78,7 +79,7 @@ ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip) // bind address if (zmq_bind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) { PrintError(); - throw sls::ZmqSocketError("Could not bind socket"); + throw ZmqSocketError("Could not bind socket"); } // sleep to allow a slow-joiner std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -90,7 +91,7 @@ int ZmqSocket::GetSendHighWaterMark() { if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_SNDHWM, &value, &value_size)) { PrintError(); - throw sls::ZmqSocketError("Could not get ZMQ_SNDHWM"); + throw ZmqSocketError("Could not get ZMQ_SNDHWM"); } return value; } @@ -99,7 +100,7 @@ void ZmqSocket::SetSendHighWaterMark(int limit) { if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SNDHWM, &limit, sizeof(limit))) { PrintError(); - throw sls::ZmqSocketError("Could not set ZMQ_SNDHWM"); + throw ZmqSocketError("Could not set ZMQ_SNDHWM"); } } @@ -109,7 +110,7 @@ int ZmqSocket::GetReceiveHighWaterMark() { if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &value, &value_size)) { PrintError(); - throw sls::ZmqSocketError("Could not get ZMQ_SNDHWM"); + throw ZmqSocketError("Could not get ZMQ_SNDHWM"); } return value; } @@ -118,7 +119,7 @@ void ZmqSocket::SetReceiveHighWaterMark(int limit) { if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &limit, sizeof(limit))) { PrintError(); - throw sls::ZmqSocketError("Could not set ZMQ_SNDHWM"); + throw ZmqSocketError("Could not set ZMQ_SNDHWM"); } } @@ -414,3 +415,6 @@ void ZmqSocket::mySocketDescriptors::Close() { contextDescriptor = nullptr; } }; + +} // namespace sls + diff --git a/slsSupportLib/src/file_utils.cpp b/slsSupportLib/src/file_utils.cpp index b38ff296b..645d0e62d 100644 --- a/slsSupportLib/src/file_utils.cpp +++ b/slsSupportLib/src/file_utils.cpp @@ -60,28 +60,28 @@ std::vector readBinaryFile(const std::string &fname, // check if it exists struct stat st; if (stat(fname.c_str(), &st) != 0) { - throw sls::RuntimeError(errorPrefix + + throw RuntimeError(errorPrefix + std::string(" (file does not exist)")); } FILE *fp = fopen(fname.c_str(), "rb"); if (fp == nullptr) { - throw sls::RuntimeError(errorPrefix + + throw RuntimeError(errorPrefix + std::string(" (Could not open file: ") + fname + std::string(")")); } // get file size to print progress - ssize_t filesize = sls::getFileSize(fp, errorPrefix); + ssize_t filesize = getFileSize(fp, errorPrefix); std::vector buffer(filesize, 0); if ((ssize_t)fread(buffer.data(), sizeof(char), filesize, fp) != filesize) { - throw sls::RuntimeError(errorPrefix + + throw RuntimeError(errorPrefix + std::string(" (Could not read file)")); } if (fclose(fp) != 0) { - throw sls::RuntimeError(errorPrefix + + throw RuntimeError(errorPrefix + std::string(" (Could not close file)")); } @@ -125,7 +125,7 @@ void mkdir_p(const std::string &path, std::string dir) { } if (mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { if (errno != EEXIST) - throw sls::RuntimeError("Could not create: " + dir); + throw RuntimeError("Could not create: " + dir); } if (i + 1 < path.length())