Skip to content
Commits on Source (4)
cmake_minimum_required(VERSION 3.9)
project(Base_DAQ)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++20")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
file(GLOB INCLUDE_FILES "include/*.h")
file(GLOB TCLAP "include/tclap")
set(CMAKE_INSTALL_MESSAGE LAZY)
......@@ -15,8 +13,3 @@ install(
FILES ${INCLUDE_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Base_DAQ"
)
install(
DIRECTORY ${TCLAP}
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)
\ No newline at end of file
#pragma once
#include <string>
#include <Base_Packet.h>
namespace inaf::oasbo::Archivers {
namespace inaf::oasbo::Archivers{
class BaseArchiver{
/**
* @brief The BaseArchiver class is an abstract base class for archivers.
*
* This class provides a common interface for archiving packets. Derived classes
* must implement the pure virtual functions defined in this class.
*/
class BaseArchiver {
protected:
std::string dest;
std::string dest; /**< The destination of the archiver. */
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;
/**
* @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;
/**
* @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;
/**
* @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 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;
/**
* @brief Destructor for the BaseArchiver class.
*/
virtual ~BaseArchiver() = default;
};
......
......@@ -5,21 +5,74 @@
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:
std::map<std::string,std::string> config;
std::map<std::string, std::string> config;
public:
/**
* @brief Read the configuration from the source.
*
* @return int Returns 0 on success, or an error code on failure.
*/
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;
/**
* @brief Push the configuration to the source.
*
* @return int Returns 0 on success, or an error code on failure.
*/
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 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 = "";
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";
}
return ret;
......
......@@ -12,6 +12,16 @@ namespace inaf::oasbo::DAQ_observers {
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 {
class BaseDAQ {
public:
......@@ -20,47 +30,105 @@ public:
};
protected:
Status currentState;
Status nextState;
bool changeStateFlag = false;
Receivers::BaseReceiver *receiver = nullptr;
Archivers::BaseArchiver *archiver = nullptr;
Providers::BaseProvider *provider = nullptr;
PacketMonitors::BasePacketMonitor *monitor = nullptr;
PacketLib::BasePacket *packet = nullptr;
std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers;
std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations;
Status currentState; /**< The current state of the DAQ system. */
Status nextState; /**< The next state of the DAQ system. */
bool changeStateFlag = false; /**< Flag indicating if the state has changed. */
Receivers::BaseReceiver *receiver = nullptr; /**< Pointer to the receiver object. */
Archivers::BaseArchiver *archiver = nullptr; /**< Pointer to the archiver object. */
Providers::BaseProvider *provider = nullptr; /**< Pointer to the provider object. */
PacketMonitors::BasePacketMonitor *monitor = nullptr; /**< Pointer to the packet monitor object. */
Packets::BasePacket *packet = nullptr; /**< Pointer to the packet object. */
std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers; /**< Vector of observers. */
std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations; /**< Vector of configurations. */
public:
/**
* @brief Sets the receiver object.
*
* @param receiver The receiver object to set.
*/
void setReceiver(Receivers::BaseReceiver &receiver) {
this->receiver = &receiver;
}
/**
* @brief Sets the archiver object.
*
* @param archiver The archiver object to set.
*/
void setArchiver(Archivers::BaseArchiver &archiver) {
this->archiver = &archiver;
}
/**
* @brief Sets the provider object.
*
* @param provider The provider object to set.
*/
void setProvider(Providers::BaseProvider &provider) {
this->provider = &provider;
}
/**
* @brief Sets the packet monitor object.
*
* @param monitor The packet monitor object to set.
*/
void setMonitor(PacketMonitors::BasePacketMonitor &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;
}
/**
* @brief Sets the current state of the DAQ system.
*
* @param currentState The current state to set.
*/
void setCurrentState(Status currentState) {
this->currentState = currentState;
}
/**
* @brief Sets the next state of the DAQ system.
*
* @param nextState The next state to set.
*/
void setNextState(Status 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) {
this->changeStateFlag = flag;
}
/**
* @brief Registers an observer to the DAQ system.
*
* @param observer The observer to register.
*/
void registerObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
observers.push_back(observer);
}
/**
* @brief Removes an observer from the DAQ system.
*
* @param observer The observer to remove.
*/
void removeObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
observers.erase(
......@@ -68,37 +136,125 @@ public:
observers.end());
}
/**
* @brief Gets a pointer to the receiver object.
*
* @return Pointer to the receiver object.
*/
Receivers::BaseReceiver* getReceiverPtr() {
return this->receiver;
}
/**
* @brief Gets a pointer to the archiver object.
*
* @return Pointer to the archiver object.
*/
Archivers::BaseArchiver* getArchiverPtr() {
return this->archiver;
}
/**
* @brief Gets a pointer to the provider object.
*
* @return Pointer to the provider object.
*/
Providers::BaseProvider* getProviderPtr() {
return this->provider;
}
/**
* @brief Gets a pointer to the packet monitor object.
*
* @return Pointer to the packet monitor object.
*/
PacketMonitors::BasePacketMonitor* getMonitorPtr() {
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;
}
/**
* @brief Gets the current state of the DAQ system.
*
* @return The current state of the DAQ system.
*/
Status getCurrentState() {
return this->currentState;
}
/**
* @brief Gets the next state of the DAQ system.
*
* @return The next state of the DAQ system.
*/
Status getNextState() {
return this->nextState;
}
/**
* @brief Gets the flag indicating if the state has changed.
*
* @return The flag indicating if the state has changed.
*/
int getChangeStateFlag() {
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;
/**
* @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 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 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() {
delete receiver;
delete provider;
......
#pragma once
#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:
inaf::oasbo::DAQ::BaseDAQ *dataAcquisition;
public:
BaseDAQ_Observer(inaf::oasbo::DAQ::BaseDAQ &dataAcquisition) {
this->dataAcquisition = &dataAcquisition;
}
virtual ~BaseDAQ_Observer() {
this->dataAcquisition->removeObserver(this);
}
virtual void updatePacketStats() = 0;
virtual void updateArchiverStats() = 0;
virtual void updateProviderStats() = 0;
virtual void updateReceiverStats() = 0;
virtual void updateAll() = 0;
virtual void start() = 0;
virtual void stop() = 0;
/**
* @brief Constructs a BaseDAQ_Observer object with the specified BaseDAQ object.
*
* @param dataAcquisition The BaseDAQ object to observe.
*/
BaseDAQ_Observer(inaf::oasbo::DAQ::BaseDAQ &dataAcquisition) {
this->dataAcquisition = &dataAcquisition;
}
/**
* @brief Destroys the BaseDAQ_Observer object and removes itself from the observed BaseDAQ object.
*/
virtual ~BaseDAQ_Observer() {
this->dataAcquisition->removeObserver(this);
}
/**
* @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
#include <string>
#include <Base_Packet.h>
#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:
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:
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 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 {
return this->stats.at(stat);
} catch (const std::out_of_range &) {
} catch (const std::out_of_range&) {
return std::nullopt;
}
}
}
/**
* @brief Default destructor.
*/
virtual ~BasePacketMonitor() = default;
};
}
This diff is collapsed.
/*
*
* Created on: Mar 1, 2021
* Author: astrisw
*
*/
#pragma once
#include <string>
#include <Base_Packet.h>
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:
std::string dest;
std::string dest; /**< The destination where packets are written to. */
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;
/**
* @brief Sets the destination where packets should be written to.
*
* @param dest The destination to be set.
*/
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;
/**
* @brief Default destructor.
*/
virtual ~BaseProvider() = default;
};
}
/*
*
* Created on: Mar 1, 2021
* Author: astrisw
*
*/
#pragma once
#include <netinet/in.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:
std::string host;
public:
/**
* @brief Get the host address.
*
* @return The host address as a string.
*/
virtual std::string getHost() = 0;
/**
* @brief Set the host address.
*
* @param host The host address to set.
*/
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;
/**
* @brief Close the connection with the client.
*
* @return An integer indicating the success or failure of the operation.
*/
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 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;
};
}