From 4ea6280522aa0cdf5b10c37ae77dd7933cba97ae Mon Sep 17 00:00:00 2001
From: Alexander Pauls <alexander.pauls@rwth-aachen.de>
Date: Tue, 27 Aug 2024 13:47:08 +0200
Subject: [PATCH 1/2] Replace GetStatus

---
 MonitorUtils/SEHMonitor.cc | 34 +++++++++++++++++++++++-----------
 tools/SEHTester.cc         | 22 +++++++++++++++-------
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/MonitorUtils/SEHMonitor.cc b/MonitorUtils/SEHMonitor.cc
index 8e42674b5..0df82c951 100644
--- a/MonitorUtils/SEHMonitor.cc
+++ b/MonitorUtils/SEHMonitor.cc
@@ -5,6 +5,7 @@
 #include "Utils/ContainerFactory.h"
 #include "Utils/Utilities.h"
 #include "Utils/ValueAndTime.h"
+#include <boost/algorithm/string.hpp>
 
 #ifdef __USE_ROOT__
 #include "TFile.h"
@@ -96,17 +97,28 @@ void SEHMonitor::runLpGBTRegisterMonitor(const std::string& registerName)
 
 void SEHMonitor::runPowerSupplyMonitor(const std::string& registerName)
 {
-    // LOG(INFO) << BOLDMAGENTA << "We pretend to be a measurement " << registerName<< RESET;
-    std::string buffer = fPowerSupplyClient->sendAndReceivePacket("GetStatus");
-    LOG(INFO) << BOLDMAGENTA << buffer << RESET;
-    // while(!(buffer.find("TimeStamp") != std::string::npos))
-    // {
-    //     buffer = fPowerSupplyClient->sendAndReceivePacket("GetStatus");
-    //     LOG(INFO) << BOLDMAGENTA << buffer << RESET;
-    // }
-    float cValue = std::stof(getVariableValue(registerName, buffer));
-    LOG(INFO) << BOLDMAGENTA << cValue << " " << registerName << RESET;
-    if((registerName.find("HV") != std::string::npos) & (registerName.find("Current") != std::string::npos)) { cValue *= 1e9; }
+    std::vector<std::string> seglist;
+    boost::split(seglist, registerName, boost::is_any_of("_"));
+    float cValue;
+
+    if((registerName.find("HV") != std::string::npos) & (registerName.find("Current") != std::string::npos)) { 
+        std::string message = "GetCurrent,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1]+ "_"  + seglist[2];
+        LOG(INFO) << BOLDMAGENTA << message << RESET;
+        std::string current = fPowerSupplyClient->sendAndReceivePacket(message);
+
+        cValue = std::stof(current);
+        LOG(INFO) << BOLDMAGENTA << registerName << " " << cValue << RESET;
+        
+        cValue *= 1e9; 
+        
+    }
+    else{
+        std::string message = "GetVoltage,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1]+ "_"  + seglist[2];
+        LOG(INFO) << BOLDMAGENTA << message << RESET;
+        std::string voltage = fPowerSupplyClient->sendAndReceivePacket(message);
+        cValue = std::stof(voltage);
+        LOG(INFO) << BOLDMAGENTA << registerName << " " << cValue << RESET;
+    }
     DetectorDataContainer thePowerSupplyContainer;
     ContainerFactory::copyAndInitDetector<ValueAndTime<float>>(*fTheSystemController->fDetectorContainer, thePowerSupplyContainer);
     thePowerSupplyContainer.getSummary<ValueAndTime<float>>() = ValueAndTime<float>(cValue, getTimeStamp());
diff --git a/tools/SEHTester.cc b/tools/SEHTester.cc
index 3847bb536..d73820017 100644
--- a/tools/SEHTester.cc
+++ b/tools/SEHTester.cc
@@ -63,8 +63,11 @@ bool SEHTester::CheckShort(std::string powerSupplyId, std::string channelId)
         LOG(ERROR) << BOLDRED << "Not connected to the power supply!!!" << RESET;
         throw std::runtime_error("Not connected to the power supply!!!");
     }
-    std::string buffer = fPowerSupplyClient->sendAndReceivePacket("GetStatus");
-    float       LvMea  = std::stof(getVariableValue(powerSupplyId + "_" + channelId + "_Voltage", buffer));
+    std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
+    std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
+    LOG(INFO) << BOLDRED << message << buffer << RESET;
+
+    float       LvMea = std::stof(buffer);
     if(LvMea == 0)
     {
         LOG(ERROR) << BOLDRED << "No output voltage at power supply, possible short detected!" << RESET;
@@ -322,9 +325,13 @@ void SEHTester::ExternalTestLeakageCurrent(uint16_t pHvSet, double measurementTi
         float IMea  = 0;
 
         clock_gettime(CLOCK_MONOTONIC, &timer);
-        std::string buffer = fPowerSupplyClient->sendAndReceivePacket("GetStatus");
-        HvMea              = std::stof(getVariableValue(powerSupplyId + "_" + channelId + "_Voltage", buffer));
-        IMea               = 1e9 * std::stof(getVariableValue(powerSupplyId + "_" + channelId + "_Current", buffer));
+        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
+        std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
+
+        message = "GetCurrent,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
+        std::string current = fPowerSupplyClient->sendAndReceivePacket(message);
+        HvMea              = std::stof(buffer);
+        IMea               = 1e9 * std::stof(current);
         // fTC_2SSEH->read_hvmon(fTC_2SSEH->Mon, UMon);
         std::this_thread::sleep_for(std::chrono::milliseconds(100));
         fTC_2SSEH->read_hvmon(fTC_2SSEH->HV_meas, ILeak);
@@ -431,8 +438,9 @@ void SEHTester::ExternalTestBiasVoltage(std::string powerSupplyId, std::string c
         setVoltageMessage = "SetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",Voltage:" + std::to_string(-1 * cHvSet) + ",";
         fPowerSupplyClient->sendAndReceivePacket(setVoltageMessage);
         std::this_thread::sleep_for(std::chrono::milliseconds(4500));
-        std::string buffer = fPowerSupplyClient->sendAndReceivePacket("GetStatus");
-        cHvMea             = std::stof(getVariableValue(powerSupplyId + "_" + channelId + "_Voltage", buffer));
+        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
+        std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
+        cHvMea = std::stof(buffer);
         // fTC_2SSEH->read_hvmon(fTC_2SSEH->Mon, cUMon);
         fTC_2SSEH->read_hvmon(fTC_2SSEH->VHVJ7, cVHVJ7);
         fTC_2SSEH->read_hvmon(fTC_2SSEH->VHVJ8, cVHVJ8);
-- 
GitLab


From d48d73976bd2b5fc75c0e34ab3367881caf369cd Mon Sep 17 00:00:00 2001
From: Alexander Pauls <alexander.pauls@rwth-aachen.de>
Date: Tue, 27 Aug 2024 13:56:16 +0200
Subject: [PATCH 2/2] format

---
 MonitorUtils/SEHMonitor.cc | 17 +++++++++--------
 tools/SEHTester.cc         | 22 +++++++++++-----------
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/MonitorUtils/SEHMonitor.cc b/MonitorUtils/SEHMonitor.cc
index 0df82c951..b62232e6a 100644
--- a/MonitorUtils/SEHMonitor.cc
+++ b/MonitorUtils/SEHMonitor.cc
@@ -101,22 +101,23 @@ void SEHMonitor::runPowerSupplyMonitor(const std::string& registerName)
     boost::split(seglist, registerName, boost::is_any_of("_"));
     float cValue;
 
-    if((registerName.find("HV") != std::string::npos) & (registerName.find("Current") != std::string::npos)) { 
-        std::string message = "GetCurrent,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1]+ "_"  + seglist[2];
+    if((registerName.find("HV") != std::string::npos) & (registerName.find("Current") != std::string::npos))
+    {
+        std::string message = "GetCurrent,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1] + "_" + seglist[2];
         LOG(INFO) << BOLDMAGENTA << message << RESET;
         std::string current = fPowerSupplyClient->sendAndReceivePacket(message);
 
         cValue = std::stof(current);
         LOG(INFO) << BOLDMAGENTA << registerName << " " << cValue << RESET;
-        
-        cValue *= 1e9; 
-        
+
+        cValue *= 1e9;
     }
-    else{
-        std::string message = "GetVoltage,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1]+ "_"  + seglist[2];
+    else
+    {
+        std::string message = "GetVoltage,PowerSupplyId:" + seglist[0] + ",ChannelId:" + seglist[1] + "_" + seglist[2];
         LOG(INFO) << BOLDMAGENTA << message << RESET;
         std::string voltage = fPowerSupplyClient->sendAndReceivePacket(message);
-        cValue = std::stof(voltage);
+        cValue              = std::stof(voltage);
         LOG(INFO) << BOLDMAGENTA << registerName << " " << cValue << RESET;
     }
     DetectorDataContainer thePowerSupplyContainer;
diff --git a/tools/SEHTester.cc b/tools/SEHTester.cc
index d73820017..8a8643f4e 100644
--- a/tools/SEHTester.cc
+++ b/tools/SEHTester.cc
@@ -63,11 +63,11 @@ bool SEHTester::CheckShort(std::string powerSupplyId, std::string channelId)
         LOG(ERROR) << BOLDRED << "Not connected to the power supply!!!" << RESET;
         throw std::runtime_error("Not connected to the power supply!!!");
     }
-    std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
-    std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
+    std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",";
+    std::string buffer  = fPowerSupplyClient->sendAndReceivePacket(message);
     LOG(INFO) << BOLDRED << message << buffer << RESET;
 
-    float       LvMea = std::stof(buffer);
+    float LvMea = std::stof(buffer);
     if(LvMea == 0)
     {
         LOG(ERROR) << BOLDRED << "No output voltage at power supply, possible short detected!" << RESET;
@@ -325,13 +325,13 @@ void SEHTester::ExternalTestLeakageCurrent(uint16_t pHvSet, double measurementTi
         float IMea  = 0;
 
         clock_gettime(CLOCK_MONOTONIC, &timer);
-        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
-        std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
+        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",";
+        std::string buffer  = fPowerSupplyClient->sendAndReceivePacket(message);
 
-        message = "GetCurrent,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
+        message             = "GetCurrent,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",";
         std::string current = fPowerSupplyClient->sendAndReceivePacket(message);
-        HvMea              = std::stof(buffer);
-        IMea               = 1e9 * std::stof(current);
+        HvMea               = std::stof(buffer);
+        IMea                = 1e9 * std::stof(current);
         // fTC_2SSEH->read_hvmon(fTC_2SSEH->Mon, UMon);
         std::this_thread::sleep_for(std::chrono::milliseconds(100));
         fTC_2SSEH->read_hvmon(fTC_2SSEH->HV_meas, ILeak);
@@ -438,9 +438,9 @@ void SEHTester::ExternalTestBiasVoltage(std::string powerSupplyId, std::string c
         setVoltageMessage = "SetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",Voltage:" + std::to_string(-1 * cHvSet) + ",";
         fPowerSupplyClient->sendAndReceivePacket(setVoltageMessage);
         std::this_thread::sleep_for(std::chrono::milliseconds(4500));
-        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId  + ",";
-        std::string buffer = fPowerSupplyClient->sendAndReceivePacket(message);
-        cHvMea = std::stof(buffer);
+        std::string message = "GetVoltage,PowerSupplyId:" + powerSupplyId + ",ChannelId:" + channelId + ",";
+        std::string buffer  = fPowerSupplyClient->sendAndReceivePacket(message);
+        cHvMea              = std::stof(buffer);
         // fTC_2SSEH->read_hvmon(fTC_2SSEH->Mon, cUMon);
         fTC_2SSEH->read_hvmon(fTC_2SSEH->VHVJ7, cVHVJ7);
         fTC_2SSEH->read_hvmon(fTC_2SSEH->VHVJ8, cVHVJ8);
-- 
GitLab