Skip to content
Commits on Source (4)
cmake_minimum_required(VERSION 3.9) cmake_minimum_required(VERSION 3.9)
project(Base_DAQ) project(Base_DAQ)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++20")
file(GLOB INCLUDE_FILES "include/*.h") file(GLOB INCLUDE_FILES "include/*.h")
file(GLOB TCLAP "include/tclap")
set(CMAKE_INSTALL_MESSAGE LAZY) set(CMAKE_INSTALL_MESSAGE LAZY)
...@@ -15,8 +13,3 @@ install( ...@@ -15,8 +13,3 @@ install(
FILES ${INCLUDE_FILES} FILES ${INCLUDE_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Base_DAQ" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Base_DAQ"
) )
install(
DIRECTORY ${TCLAP}
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)
\ No newline at end of file
#pragma once #pragma once
#include <string> #include <string>
#include <Base_Packet.h> #include <Base_Packet.h>
namespace inaf::oasbo::Archivers {
namespace inaf::oasbo::Archivers{ /**
* @brief The BaseArchiver class is an abstract base class for archivers.
*
class BaseArchiver{ * This class provides a common interface for archiving packets. Derived classes
* must implement the pure virtual functions defined in this class.
*/
class BaseArchiver {
protected: protected:
std::string dest; std::string dest; /**< The destination of the archiver. */
public: public:
virtual int write(PacketLib::BasePacket &) = 0; /**
virtual int write(PacketLib::BasePacket &, std::string destination) = 0; * @brief Write a packet to the archiver.
*
* This function writes the given packet to the "archive".
*
* @param packet The packet to write.
* @return An integer indicating the success or failure of the write operation.
*/
virtual int write(Packets::BasePacket&) = 0;
/**
* @brief Write a packet to the archiver with a specified destination.
*
* This function writes the given packet to the archiver with the specified destination.
*
* @param packet The packet to write.
* @param destination The destination where the packet should be written.
* @return An integer indicating the success or failure of the write operation.
*/
virtual int write(Packets::BasePacket&, std::string destination) = 0;
/**
* @brief Open the archiver.
*
* This function opens the archiver.
*
* @return An integer indicating the success or failure of the open operation.
*/
virtual int open()=0; virtual int open()=0;
/**
* @brief Close the archiver.
*
* This function closes the archiver.
*
* @return An integer indicating the success or failure of the close operation.
*/
virtual int close()=0; virtual int close()=0;
/**
* @brief Check if the archiver is open.
*
* This function checks if the archiver is open.
*
* @return A boolean value indicating whether the archiver is open or not.
*/
virtual bool is_open()=0; virtual bool is_open()=0;
/**
* @brief Set the destination of the archiver.
*
* This function sets the destination of the archiver.
*
* @param dest The destination to set.
*/
virtual void setDest(std::string dest) = 0; virtual void setDest(std::string dest) = 0;
virtual void updateDest()=0;
/**
* @brief Get the destination of the archiver.
*
* This function gets the destination of the archiver.
*
* @return The destination of the archiver.
*/
virtual std::string getDest() = 0; virtual std::string getDest() = 0;
/**
* @brief Destructor for the BaseArchiver class.
*/
virtual ~BaseArchiver() = default; virtual ~BaseArchiver() = default;
}; };
......
...@@ -5,21 +5,74 @@ ...@@ -5,21 +5,74 @@
namespace inaf::oasbo::Configurators { namespace inaf::oasbo::Configurators {
class BaseConfigurator{ /**
* @brief The BaseConfigurator class is an abstract base class for configurators in the DAQ system.
*
* It provides common functionality for reading and pushing configurations to a source,
* as well as inserting new configurations into the existing ones.
*/
class BaseConfigurator {
protected: protected:
std::map<std::string,std::string> config; std::map<std::string, std::string> config;
public: public:
/**
* @brief Read the configuration from the source.
*
* @return int Returns 0 on success, or an error code on failure.
*/
virtual int readConfigFromSource() = 0; virtual int readConfigFromSource() = 0;
/**
* @brief Read the configuration for the specified target.
*
* @param target The target for which to read the configuration.
* @return int Returns 0 on success, or an error code on failure.
*/
virtual int readConfigFromSource(std::string target) = 0; virtual int readConfigFromSource(std::string target) = 0;
/**
* @brief Push the configuration to the source.
*
* @return int Returns 0 on success, or an error code on failure.
*/
virtual int pushConfigToSource() = 0; virtual int pushConfigToSource() = 0;
/**
* @brief Push the configuration for the specified target.
*
* @param target The target for which to push the configuration.
* @return int Returns 0 on success, or an error code on failure.
*/
virtual int pushConfigToSource(std::string target) = 0; virtual int pushConfigToSource(std::string target) = 0;
virtual int insert(std::map<std::string, std::string>, std::string target) = 0;
virtual std::map<std::string, std::string> getConfig() {return this->config;}
std::string toString(){ /**
* @brief Insert new configurations into the existing ones.
*
* @param newConfig The new configurations to insert.
* @param target The target for which to insert the new configurations.
* @return int Returns 0 on success, or an error code on failure.
*/
virtual int insert(std::map<std::string, std::string> newConfig,
std::string target) = 0;
/**
* @brief Get the current configuration.
*
* @return std::map<std::string, std::string> The current configuration.
*/
virtual std::map<std::string, std::string> getConfig() {
return this->config;
}
/**
* @brief Convert the configuration to a string representation.
*
* @return std::string The string representation of the configuration.
*/
std::string toString() {
std::string ret = ""; std::string ret = "";
for( const std::pair<std::string, std::string> n : config) { for (const std::pair<std::string, std::string> n : config) {
ret += n.first + " : " + n.second + "\n"; ret += n.first + " : " + n.second + "\n";
} }
return ret; return ret;
......
...@@ -12,6 +12,16 @@ namespace inaf::oasbo::DAQ_observers { ...@@ -12,6 +12,16 @@ namespace inaf::oasbo::DAQ_observers {
class BaseDAQ_Observer; class BaseDAQ_Observer;
} }
/**
* @brief The BaseDAQ class represents the base class for a Data Acquisition (DAQ) system.
*
* This class provides a common interface and functionality for a DAQ system. The DAQ system is imagined as a state machine.
* This super class defines the states, sets the receiver, archiver, provider, monitor, and packet objects, and
* manages the observers and configurations. It also provides pure virtual functions for
* starting, stopping, switching states, delivering packets, and getting the state as a string.
*
* @note This class is meant to be inherited from and should not be instantiated directly.
*/
namespace inaf::oasbo::DAQ { namespace inaf::oasbo::DAQ {
class BaseDAQ { class BaseDAQ {
public: public:
...@@ -20,47 +30,105 @@ public: ...@@ -20,47 +30,105 @@ public:
}; };
protected: protected:
Status currentState; Status currentState; /**< The current state of the DAQ system. */
Status nextState; Status nextState; /**< The next state of the DAQ system. */
bool changeStateFlag = false; bool changeStateFlag = false; /**< Flag indicating if the state has changed. */
Receivers::BaseReceiver *receiver = nullptr; Receivers::BaseReceiver *receiver = nullptr; /**< Pointer to the receiver object. */
Archivers::BaseArchiver *archiver = nullptr; Archivers::BaseArchiver *archiver = nullptr; /**< Pointer to the archiver object. */
Providers::BaseProvider *provider = nullptr; Providers::BaseProvider *provider = nullptr; /**< Pointer to the provider object. */
PacketMonitors::BasePacketMonitor *monitor = nullptr; PacketMonitors::BasePacketMonitor *monitor = nullptr; /**< Pointer to the packet monitor object. */
PacketLib::BasePacket *packet = nullptr; Packets::BasePacket *packet = nullptr; /**< Pointer to the packet object. */
std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers; std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers; /**< Vector of observers. */
std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations; std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations; /**< Vector of configurations. */
public: public:
/**
* @brief Sets the receiver object.
*
* @param receiver The receiver object to set.
*/
void setReceiver(Receivers::BaseReceiver &receiver) { void setReceiver(Receivers::BaseReceiver &receiver) {
this->receiver = &receiver; this->receiver = &receiver;
} }
/**
* @brief Sets the archiver object.
*
* @param archiver The archiver object to set.
*/
void setArchiver(Archivers::BaseArchiver &archiver) { void setArchiver(Archivers::BaseArchiver &archiver) {
this->archiver = &archiver; this->archiver = &archiver;
} }
/**
* @brief Sets the provider object.
*
* @param provider The provider object to set.
*/
void setProvider(Providers::BaseProvider &provider) { void setProvider(Providers::BaseProvider &provider) {
this->provider = &provider; this->provider = &provider;
} }
/**
* @brief Sets the packet monitor object.
*
* @param monitor The packet monitor object to set.
*/
void setMonitor(PacketMonitors::BasePacketMonitor &monitor) { void setMonitor(PacketMonitors::BasePacketMonitor &monitor) {
this->monitor = &monitor; this->monitor = &monitor;
} }
void setPacket(PacketLib::BasePacket &packet) {
/**
* @brief Sets the packet object.
*
* @param packet The packet object to set.
*/
void setPacket(Packets::BasePacket &packet) {
this->packet = &packet; this->packet = &packet;
} }
/**
* @brief Sets the current state of the DAQ system.
*
* @param currentState The current state to set.
*/
void setCurrentState(Status currentState) { void setCurrentState(Status currentState) {
this->currentState = currentState; this->currentState = currentState;
} }
/**
* @brief Sets the next state of the DAQ system.
*
* @param nextState The next state to set.
*/
void setNextState(Status nextState) { void setNextState(Status nextState) {
this->nextState = nextState; this->nextState = nextState;
} }
/**
* @brief Sets the flag indicating if the state has changed.
*
* @param flag The flag value to set.
*/
void setChangeStateFlag(bool flag) { void setChangeStateFlag(bool flag) {
this->changeStateFlag = flag; this->changeStateFlag = flag;
} }
/**
* @brief Registers an observer to the DAQ system.
*
* @param observer The observer to register.
*/
void registerObserver( void registerObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) { inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
observers.push_back(observer); observers.push_back(observer);
} }
/**
* @brief Removes an observer from the DAQ system.
*
* @param observer The observer to remove.
*/
void removeObserver( void removeObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) { inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
observers.erase( observers.erase(
...@@ -68,37 +136,125 @@ public: ...@@ -68,37 +136,125 @@ public:
observers.end()); observers.end());
} }
/**
* @brief Gets a pointer to the receiver object.
*
* @return Pointer to the receiver object.
*/
Receivers::BaseReceiver* getReceiverPtr() { Receivers::BaseReceiver* getReceiverPtr() {
return this->receiver; return this->receiver;
} }
/**
* @brief Gets a pointer to the archiver object.
*
* @return Pointer to the archiver object.
*/
Archivers::BaseArchiver* getArchiverPtr() { Archivers::BaseArchiver* getArchiverPtr() {
return this->archiver; return this->archiver;
} }
/**
* @brief Gets a pointer to the provider object.
*
* @return Pointer to the provider object.
*/
Providers::BaseProvider* getProviderPtr() { Providers::BaseProvider* getProviderPtr() {
return this->provider; return this->provider;
} }
/**
* @brief Gets a pointer to the packet monitor object.
*
* @return Pointer to the packet monitor object.
*/
PacketMonitors::BasePacketMonitor* getMonitorPtr() { PacketMonitors::BasePacketMonitor* getMonitorPtr() {
return this->monitor; return this->monitor;
} }
PacketLib::BasePacket* getPacketPrt() {
/**
* @brief Gets a pointer to the packet object.
*
* @return Pointer to the packet object.
*/
Packets::BasePacket* getPacketPrt() {
return this->packet; return this->packet;
} }
/**
* @brief Gets the current state of the DAQ system.
*
* @return The current state of the DAQ system.
*/
Status getCurrentState() { Status getCurrentState() {
return this->currentState; return this->currentState;
} }
/**
* @brief Gets the next state of the DAQ system.
*
* @return The next state of the DAQ system.
*/
Status getNextState() { Status getNextState() {
return this->nextState; return this->nextState;
} }
/**
* @brief Gets the flag indicating if the state has changed.
*
* @return The flag indicating if the state has changed.
*/
int getChangeStateFlag() { int getChangeStateFlag() {
return this->changeStateFlag; return this->changeStateFlag;
} }
/**
* @brief Starts the DAQ system.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual void start() = 0; virtual void start() = 0;
/**
* @brief Stops the DAQ system.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual void stop() = 0; virtual void stop() = 0;
virtual void switchState(const Status) = 0;
/**
* @brief Switches the state of the DAQ system.
*
* @param state The state to switch to.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual void switchState(const Status state) = 0;
/**
* @brief Delivers a packet after received. It should probably call the provider to deliver the packet.
*
* @return The result of the packet delivery.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual int deliverPacket() = 0; virtual int deliverPacket() = 0;
virtual std::string getStateStr(const Status) = 0;
/**
* @brief Gets the string representation of a state.
*
* @param state The state to get the string representation of.
* @return The string representation of the state.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual std::string getStateStr(const Status state) = 0;
/**
* @brief Destructor for the BaseDAQ class.
*
* Deletes the receiver, provider, archiver, monitor, packet, and observers.
*/
virtual ~BaseDAQ() { virtual ~BaseDAQ() {
delete receiver; delete receiver;
delete provider; delete provider;
......
#pragma once #pragma once
#include <Base_DAQ.h> #include <Base_DAQ.h>
namespace inaf::oasbo::DAQ_observers{ /**
* @brief The BaseDAQ_Observer class is an abstract base class for DAQ system observers.
*
* This class defines the interface for observing the statistics and status of a BaseDAQ object.
* Subclasses of BaseDAQ_Observer must implement the pure virtual functions defined in this class.
*
*/
namespace inaf::oasbo::DAQ_observers {
class BaseDAQ_Observer{ class BaseDAQ_Observer {
protected: protected:
inaf::oasbo::DAQ::BaseDAQ *dataAcquisition; inaf::oasbo::DAQ::BaseDAQ *dataAcquisition;
public: public:
BaseDAQ_Observer(inaf::oasbo::DAQ::BaseDAQ &dataAcquisition) { /**
this->dataAcquisition = &dataAcquisition; * @brief Constructs a BaseDAQ_Observer object with the specified BaseDAQ object.
} *
* @param dataAcquisition The BaseDAQ object to observe.
virtual ~BaseDAQ_Observer() { */
this->dataAcquisition->removeObserver(this); BaseDAQ_Observer(inaf::oasbo::DAQ::BaseDAQ &dataAcquisition) {
} this->dataAcquisition = &dataAcquisition;
}
virtual void updatePacketStats() = 0;
virtual void updateArchiverStats() = 0; /**
virtual void updateProviderStats() = 0; * @brief Destroys the BaseDAQ_Observer object and removes itself from the observed BaseDAQ object.
virtual void updateReceiverStats() = 0; */
virtual void updateAll() = 0; virtual ~BaseDAQ_Observer() {
virtual void start() = 0; this->dataAcquisition->removeObserver(this);
virtual void stop() = 0; }
/**
* @brief Updates the packet statistics of the observed BaseDAQ object.
*/
virtual void updatePacketStats() = 0;
/**
* @brief Updates the archiver statistics of the observed BaseDAQ object.
*/
virtual void updateArchiverStats() = 0;
/**
* @brief Updates the provider statistics of the observed BaseDAQ object.
*/
virtual void updateProviderStats() = 0;
/**
* @brief Updates the receiver statistics of the observed BaseDAQ object.
*/
virtual void updateReceiverStats() = 0;
/**
* @brief Updates all statistics of the observed BaseDAQ object.
*/
virtual void updateAll() = 0;
/**
* @brief Starts the observation on the BaseDAQ object.
*/
virtual void start() = 0;
/**
* @brief Stops the observation on the BaseDAQ object.
*/
virtual void stop() = 0;
}; };
} }
#pragma once #pragma once
#include <string> #include <string>
#include <Base_Packet.h> #include <Base_Packet.h>
#include <map> #include <map>
namespace inaf::oasbo::PacketMonitors{ namespace inaf::oasbo::PacketMonitors {
class BasePacketMonitor{ /**
* @brief The BasePacketMonitor class is an abstract base class for packet monitors in the DAQ system.
*
* This class provides a common interface for packet monitoring functionality.
* Derived classes must implement the monit(), printStats(), and reset() methods.
* The class also provides methods to access and retrieve statistics related to the monitored packets.
*/
class BasePacketMonitor {
protected: protected:
std::map<std::string, std::string> stats; std::map<std::string, std::string> stats; /**< A map to store statistics related to the monitored packets. */
public: public:
virtual void monit(PacketLib::BasePacket &) = 0; /**
virtual void printStats()=0; * @brief Monitors a packet.
*
* This pure virtual method is used to monitor a packet.
* Derived classes must implement this method to define the monitoring behavior.
*
* @param packet The packet to be monitored.
*/
virtual void monit(Packets::BasePacket &packet) = 0;
/**
* @brief Prints the statistics related to the monitored packets.
*
* This pure virtual method is used to print the statistics related to the monitored packets.
* Derived classes must implement this method to define the printing behavior.
*/
virtual void printStats() = 0;
/**
* @brief Resets the statistics related to the monitored packets.
*
* This pure virtual method is used to reset the statistics related to the monitored packets.
* Derived classes must implement this method to define the resetting behavior.
*/
virtual void reset() = 0; virtual void reset() = 0;
virtual std::map<std::string, std::string> getStatsMap() const { return stats;}
std::optional<std::string> getStat(std::string stat) const { /**
* @brief Retrieves the statistics map.
*
* This method returns the map containing the statistics related to the monitored packets.
*
* @return The map containing the statistics related to the monitored packets.
*/
virtual std::map<std::string, std::string> getStatsMap() const {
return stats;
}
/**
* @brief Retrieves a specific statistic.
*
* This method retrieves a specific statistic from the statistics map.
* If the statistic is not found, it returns std::nullopt.
*
* @param stat The name of the statistic to retrieve.
* @return An optional string containing the value of the statistic, or std::nullopt if the statistic is not found.
*/
std::optional<std::string> getStat(std::string stat) const {
try { try {
return this->stats.at(stat); return this->stats.at(stat);
} catch (const std::out_of_range &) { } catch (const std::out_of_range&) {
return std::nullopt; return std::nullopt;
} }
} }
/**
* @brief Default destructor.
*/
virtual ~BasePacketMonitor() = default; virtual ~BasePacketMonitor() = default;
}; };
} }
This diff is collapsed.
/*
*
* Created on: Mar 1, 2021
* Author: astrisw
*
*/
#pragma once #pragma once
#include <string> #include <string>
#include <Base_Packet.h> #include <Base_Packet.h>
namespace inaf::oasbo::Providers { namespace inaf::oasbo::Providers {
class BaseProvider{ /**
* @brief The BaseProvider class is an abstract base class for providers in the DAQ system.
*
* This class defines the common interface for providers that write packets to a destination.
* Derived classes must implement the pure virtual functions defined in this class.
*/
class BaseProvider {
protected: protected:
std::string dest; std::string dest; /**< The destination where packets are written to. */
public: public:
virtual int write(PacketLib::BasePacket &) = 0; /**
virtual int write(PacketLib::BasePacket &, std::string dest) = 0; * @brief Writes a packet to the destination.
*
* @param packet The packet to be written.
* @return int Returns an integer indicating the success or failure of the write operation.
*/
virtual int write(Packets::BasePacket &packet) = 0;
/**
* @brief Writes a packet to a specified destination.
*
* @param packet The packet to be written.
* @param dest The destination where the packet should be written to.
* @return int Returns an integer indicating the success or failure of the write operation.
*/
virtual int write(Packets::BasePacket &packet, std::string dest) = 0;
virtual int open()=0; /**
virtual int close()=0; * @brief Opens the provider.
*
* @return int Returns an integer indicating the success or failure of the open operation.
*/
virtual int open() = 0;
/**
* @brief Closes the provider.
*
* @return int Returns an integer indicating the success or failure of the close operation.
*/
virtual int close() = 0;
/**
* @brief Checks if the provider is open.
*
* @return bool Returns true if the provider is open, false otherwise.
*/
virtual bool isOpen() = 0; virtual bool isOpen() = 0;
/**
* @brief Sets the destination where packets should be written to.
*
* @param dest The destination to be set.
*/
virtual void setDest(std::string dest) = 0; virtual void setDest(std::string dest) = 0;
/**
* @brief Gets the current destination where packets are written to.
*
* @return std::string Returns the current destination.
*/
virtual std::string getDest() = 0; virtual std::string getDest() = 0;
/**
* @brief Default destructor.
*/
virtual ~BaseProvider() = default; virtual ~BaseProvider() = default;
}; };
} }
/*
*
* Created on: Mar 1, 2021
* Author: astrisw
*
*/
#pragma once #pragma once
#include <netinet/in.h> #include <netinet/in.h>
#include <Base_Packet.h> #include <Base_Packet.h>
namespace inaf::oasbo::Receivers{ namespace inaf::oasbo::Receivers {
class BaseReceiver{ /**
* @brief The BaseReceiver class is an abstract base class for receivers in the DAQ system.
*
* This class provides a common interface for receiving data from clients. It defines pure virtual
* functions for getting and setting the host, connecting to and closing the connection with the client,
* checking if the receiver is connected to the client, and receiving data from the client.
*
* Derived classes must implement these functions according to their specific requirements.
*/
class BaseReceiver {
protected: protected:
std::string host; std::string host;
public: public:
/**
* @brief Get the host address.
*
* @return The host address as a string.
*/
virtual std::string getHost() = 0; virtual std::string getHost() = 0;
/**
* @brief Set the host address.
*
* @param host The host address to set.
*/
virtual void setHost(std::string host) = 0; virtual void setHost(std::string host) = 0;
/**
* @brief Connect to the client.
*
* @return An integer indicating the success or failure of the operation.
*/
virtual int connectToClient()=0; virtual int connectToClient()=0;
/**
* @brief Close the connection with the client.
*
* @return An integer indicating the success or failure of the operation.
*/
virtual int closeConnectionToClient()=0; virtual int closeConnectionToClient()=0;
/**
* @brief Check if the receiver is connected to the client.
*
* @return true if the receiver is connected to the client, false otherwise.
*/
virtual bool isConnectedToClient() const =0; virtual bool isConnectedToClient() const =0;
virtual int receiveFromClient(PacketLib::BasePacket &) = 0;
/**
* @brief Receive data from the client.
*
* @param packet The received packet will be stored in this parameter.
* @return An integer indicating the success or failure of the operation.
*/
virtual int receiveFromClient(Packets::BasePacket&) = 0;
/**
* @brief Virtual destructor.
*/
virtual ~BaseReceiver() = default; virtual ~BaseReceiver() = default;
}; };
} }