Commit 146e4540 authored by Module Testing's avatar Module Testing
Browse files

Formatted code

parent 0924336f
......@@ -455,7 +455,7 @@ bool D19cFWInterface::GBTLock(const BeBoard* pBoard)
} while(std::cin.get() != '\n');
// system("/home/modtest/Programming/power_supply/bin/TurnOn -c /home/modtest/Programming/power_supply/config/config.xml ");
// std::this_thread::sleep_for (std::chrono::milliseconds (1000) );
for(auto cLinkId: cLinkIds)
{
// reset here for good measure
......
......@@ -8,7 +8,6 @@
#include <sstream>
#include <strings.h> // bzero
#include <thread>
#include <sstream>
//========================================================================================================================
TCPClientBase::TCPClientBase(const std::string& serverIP, int serverPort) : fServerIP(serverIP), fServerPort(serverPort), fConnected(false) {}
......
......@@ -13,10 +13,7 @@
// using namespace ots;
//========================================================================================================================
TCPServerBase::TCPServerBase(unsigned int serverPort, unsigned int maxNumberOfClients)
: fMaxNumberOfClients(maxNumberOfClients)
, fServerPort(serverPort)
, fAccept(true)
TCPServerBase::TCPServerBase(unsigned int serverPort, unsigned int maxNumberOfClients) : fMaxNumberOfClients(maxNumberOfClients), fServerPort(serverPort), fAccept(true)
{
// CANNOT GO IN THE CONSTRUCTOR OR IT MIGHT START BEFORE THE CHILD CLASS CONSTRUCTOR IS FULLY CONSTRUCTED
// THIS MIGHT RESULT IN THE CALL OF THE VIRTUAL TCPServerBase::acceptConnections
......@@ -41,34 +38,34 @@ TCPServerBase::~TCPServerBase(void)
//========================================================================================================================
void TCPServerBase::startAccept(void)
{
// __COUT__ << "Begin startAccept" << std::endl;
int opt = 1; // SO_REUSEADDR - man socket(7)
if(::setsockopt(getSocketId(), SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)) == -1)
{
close();
throw std::runtime_error(std::string("Setsockopt: ") + strerror(errno));
}
// __COUT__ << "Begin startAccept" << std::endl;
int opt = 1; // SO_REUSEADDR - man socket(7)
if(::setsockopt(getSocketId(), SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)) == -1)
{
close();
throw std::runtime_error(std::string("Setsockopt: ") + strerror(errno));
}
struct sockaddr_in serverAddr;
bzero((char*)&serverAddr, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(fServerPort);
serverAddr.sin_addr.s_addr = INADDR_ANY;
struct sockaddr_in serverAddr;
bzero((char*)&serverAddr, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(fServerPort);
serverAddr.sin_addr.s_addr = INADDR_ANY;
if(::bind(getSocketId(), (struct sockaddr*)&serverAddr, sizeof(serverAddr)) != 0)
{
close();
throw std::runtime_error(std::string("Bind: ") + strerror(errno));
}
//freeaddrinfo(serverAddr); // all done with this structure
if(::bind(getSocketId(), (struct sockaddr*)&serverAddr, sizeof(serverAddr)) != 0)
{
close();
throw std::runtime_error(std::string("Bind: ") + strerror(errno));
}
// freeaddrinfo(serverAddr); // all done with this structure
if(::listen(getSocketId(), fMaxConnectionBacklog) != 0)
{
close();
throw std::runtime_error(std::string("Listen: ") + strerror(errno));
}
fAccept = true;
fAcceptFuture = std::async(std::launch::async, &TCPServerBase::acceptConnections, this);
if(::listen(getSocketId(), fMaxConnectionBacklog) != 0)
{
close();
throw std::runtime_error(std::string("Listen: ") + strerror(errno));
}
fAccept = true;
fAcceptFuture = std::async(std::launch::async, &TCPServerBase::acceptConnections, this);
}
// An accepts waits for a connection and returns the opened socket number
......
......@@ -1028,9 +1028,8 @@ void FileParser::parseRD53Settings(pugi::xml_node theChipNode, ReadoutChip* theC
}
}
std::string FileParser::parseMonitor (const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile)
std::string FileParser::parseMonitor(const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile)
{
if(pIsFile && pFilename.find(".xml") != std::string::npos)
return parseMonitorxml(pFilename, theDetectorMonitorConfig, os, pIsFile);
else if(!pIsFile)
......@@ -1040,7 +1039,7 @@ std::string FileParser::parseMonitor (const std::string& pFilename, DetectorMoni
return "None";
}
std::string FileParser::parseMonitorxml (const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile)
std::string FileParser::parseMonitorxml(const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile)
{
pugi::xml_document doc;
pugi::xml_parse_result result;
......@@ -1061,7 +1060,7 @@ std::string FileParser::parseMonitorxml (const std::string& pFilename, DetectorM
return "None";
}
if (!bool(doc.child("MonitoringSettings")))
if(!bool(doc.child("MonitoringSettings")))
{
os << BOLDYELLOW << "Monitoring not defined in " << pFilename << RESET << std::endl;
os << BOLDYELLOW << "No monitoring will be run" << RESET << std::endl;
......@@ -1076,7 +1075,7 @@ std::string FileParser::parseMonitorxml (const std::string& pFilename, DetectorM
for(pugi::xml_node monitorElement = theMonitorNode.child("Enable"); monitorElement; monitorElement = monitorElement.next_sibling())
{
std::string monitorElementName = monitorElement.attribute("name").value();
if(atoi(monitorElement.first_child().value())>0)
if(atoi(monitorElement.first_child().value()) > 0)
{
theDetectorMonitorConfig.fMonitorElementList.emplace_back(std::move(monitorElementName));
os << BOLDRED << "Monitoring:" << RESET << " -- " << BOLDCYAN << monitorElementName << RESET << std::endl;
......@@ -1085,10 +1084,8 @@ std::string FileParser::parseMonitorxml (const std::string& pFilename, DetectorM
if(theDetectorMonitorConfig.fMonitorElementList.size() == 0) return "None";
return theMonitorNode.attribute("type").value();
}
// ########################
} // namespace Ph2_System
......@@ -18,10 +18,10 @@
#include "../HWInterface/RD53FWInterface.h"
#include "../Utils/ConditionDataSet.h"
#include "../Utils/ConsoleColor.h"
#include "../Utils/DetectorMonitorConfig.h"
#include "../Utils/Exception.h"
#include "../Utils/Utilities.h"
#include "../Utils/easylogging++.h"
#include "../Utils/DetectorMonitorConfig.h"
#include "pugixml.hpp"
#include <iostream>
......@@ -50,9 +50,9 @@ class FileParser
FileParser() {}
~FileParser() {}
void parseHW(const std::string& pFilename, BeBoardFWMap& pBeBoardFWMap, DetectorContainer* pDetectorContainer, std::ostream& os, bool pIsFile);
void parseSettings(const std::string& pFilename, SettingsMap& pSettingsMap, std::ostream& os, bool pIsFile);
std::string parseMonitor (const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile);
void parseHW(const std::string& pFilename, BeBoardFWMap& pBeBoardFWMap, DetectorContainer* pDetectorContainer, std::ostream& os, bool pIsFile);
void parseSettings(const std::string& pFilename, SettingsMap& pSettingsMap, std::ostream& os, bool pIsFile);
std::string parseMonitor(const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile);
protected:
/*!
......@@ -77,7 +77,7 @@ class FileParser
*/
void parseSettingsxml(const std::string& pFilename, SettingsMap& pSettingsMap, std::ostream& os, bool pIsFile);
std::string parseMonitorxml (const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile);
std::string parseMonitorxml(const std::string& pFilename, DetectorMonitorConfig& theDetectorMonitorConfig, std::ostream& os, bool pIsFile);
void parseBeBoard(pugi::xml_node pBeBordNode, BeBoardFWMap& pBeBoardFWMap, DetectorContainer* pDetectorContainer, std::ostream& os);
void parseRegister(pugi::xml_node pRegisterNode, std::string& pAttributeString, double& pValue, Ph2_HwDescription::BeBoard* pBoard, std::ostream& os);
......
......@@ -8,8 +8,8 @@
*/
#include "SystemController.h"
#include "../tools/CBCMonitor.h"
#include "../Utils/DetectorMonitorConfig.h"
#include "../tools/CBCMonitor.h"
using namespace Ph2_HwDescription;
using namespace Ph2_HwInterface;
......@@ -54,14 +54,11 @@ void SystemController::Destroy()
if(fDetectorMonitor != nullptr)
{
fDetectorMonitor->stopMonitoring();
while(fMonitorFuture.wait_for(std::chrono::milliseconds(250)) != std::future_status::ready)
{
LOG(INFO) << "Waiting for monitoring to be completed...";
}
while(fMonitorFuture.wait_for(std::chrono::milliseconds(250)) != std::future_status::ready) { LOG(INFO) << "Waiting for monitoring to be completed..."; }
delete fDetectorMonitor;
fDetectorMonitor = nullptr;
}
this->closeFileHandler();
delete fBeBoardInterface;
......@@ -186,7 +183,7 @@ void SystemController::InitializeHw(const std::string& pFilename, std::ostream&
if(fWriteHandlerEnabled == true) this->initializeWriteFileHandler();
DetectorMonitorConfig theDetectorMonitorConfig;
std::string monitoringType = fParser.parseMonitor(pFilename, theDetectorMonitorConfig, os, pIsFile);
std::string monitoringType = fParser.parseMonitor(pFilename, theDetectorMonitorConfig, os, pIsFile);
if(monitoringType != "None")
{
......@@ -197,9 +194,9 @@ void SystemController::InitializeHw(const std::string& pFilename, std::ostream&
LOG(ERROR) << "Unrecognized monitor type, Aborting";
abort();
}
fDetectorMonitor->Inherit(this);
fMonitorFuture = std::async(std::launch::async, std::ref(*fDetectorMonitor));
fMonitorFuture = std::async(std::launch::async, std::ref(*fDetectorMonitor));
}
}
......
#ifndef DETECTOR_MONITOR_CONFIG_H
#define DETECTOR_MONITOR_CONFIG_H
#include <vector>
#include <algorithm>
#include <string>
#include <algorithm>
#include <vector>
struct DetectorMonitorConfig
{
std::vector<std::string> fMonitorElementList;
int fSleepTimeMs;
int fSleepTimeMs;
bool isElementToMonitor(std::string theElement)
{
return (find(fMonitorElementList.begin(), fMonitorElementList.end(), theElement) != fMonitorElementList.end());
}
bool isElementToMonitor(std::string theElement) { return (find(fMonitorElementList.begin(), fMonitorElementList.end(), theElement) != fMonitorElementList.end()); }
};
#endif
\ No newline at end of file
......@@ -357,8 +357,8 @@ int main(int argc, char* argv[])
cTool.WriteRootFile();
cTool.CloseResultFile();
cTool.Destroy();
system("/home/modtest/Programming/power_supply/bin/TurnOff -c /home/modtest/Programming/power_supply/config/config.xml ");
// system("/home/modtest/Programming/power_supply/bin/TurnOff -c /home/modtest/Programming/power_supply/config/config.xml ");
if(!batchMode) cApp.Run();
cGlobalTimer.stop();
......
#include "CBCMonitor.h"
#include "../HWDescription/OuterTrackerHybrid.h"
#include "thread"
#include "chrono"
#include "thread"
using namespace Ph2_HwDescription;
using namespace Ph2_HwInterface;
CBCMonitor::CBCMonitor(DetectorMonitorConfig theDetectorMonitorConfig)
: DetectorMonitor(theDetectorMonitorConfig)
CBCMonitor::CBCMonitor(DetectorMonitorConfig theDetectorMonitorConfig) : DetectorMonitor(theDetectorMonitorConfig)
{
doMonitorTemperature = fDetectorMonitorConfig.isElementToMonitor("ModuleTemperature");
}
......@@ -19,15 +18,15 @@ void CBCMonitor::runMonitor()
void CBCMonitor::runTemperatureMonitor()
{
for(const auto& board : *fDetectorContainer)
for(const auto& board: *fDetectorContainer)
{
for(const auto& opticalGroup : *board)
for(const auto& opticalGroup: *board)
{
for(const auto& hybrid : *opticalGroup)
{
uint16_t cbcOrMpa = fCicInterface->ReadChipReg(static_cast<const OuterTrackerHybrid*>(hybrid)->fCic, "CBCMPA_SEL"); //just to read something
LOG(INFO) << BOLDMAGENTA << "Hybrid " << hybrid->getId() << " - CBCMPA_SEL = " << cbcOrMpa << RESET;
}
for(const auto& hybrid: *opticalGroup)
{
uint16_t cbcOrMpa = fCicInterface->ReadChipReg(static_cast<const OuterTrackerHybrid*>(hybrid)->fCic, "CBCMPA_SEL"); // just to read something
LOG(INFO) << BOLDMAGENTA << "Hybrid " << hybrid->getId() << " - CBCMPA_SEL = " << cbcOrMpa << RESET;
}
}
}
}
......@@ -5,13 +5,13 @@
class CBCMonitor : public DetectorMonitor
{
public:
CBCMonitor(DetectorMonitorConfig theDetectorMonitorConfig);
public:
CBCMonitor(DetectorMonitorConfig theDetectorMonitorConfig);
private:
virtual void runMonitor() override;
void runTemperatureMonitor();
bool doMonitorTemperature {false};
private:
virtual void runMonitor() override;
void runTemperatureMonitor();
bool doMonitorTemperature{false};
};
#endif
\ No newline at end of file
#include "DetectorMonitor.h"
#include "thread"
#include "chrono"
#include "thread"
DetectorMonitor::DetectorMonitor(DetectorMonitorConfig theDetectorMonitorConfig)
: fDetectorMonitorConfig(theDetectorMonitorConfig)
{
}
DetectorMonitor::DetectorMonitor(DetectorMonitorConfig theDetectorMonitorConfig) : fDetectorMonitorConfig(theDetectorMonitorConfig) {}
void DetectorMonitor::operator()()
{
......
......@@ -6,15 +6,15 @@
class DetectorMonitor : public Ph2_System::SystemController
{
public:
DetectorMonitor(DetectorMonitorConfig theDetectorMonitorConfig);
void operator()();
void stopMonitoring() {fKeepRunning = false;}
protected:
virtual void runMonitor() = 0;
std::atomic<bool> fKeepRunning {true};
DetectorMonitorConfig fDetectorMonitorConfig;
public:
DetectorMonitor(DetectorMonitorConfig theDetectorMonitorConfig);
void operator()();
void stopMonitoring() { fKeepRunning = false; }
protected:
virtual void runMonitor() = 0;
std::atomic<bool> fKeepRunning{true};
DetectorMonitorConfig fDetectorMonitorConfig;
};
#endif
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment