Skip to content
Base_Monitor.h 2.4 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
#pragma once
Valerio Pastore's avatar
Valerio Pastore committed
#include <string>
Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Packet.h>
Valerio Pastore's avatar
Valerio Pastore committed
#include <map>
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
.  
Valerio Pastore committed
namespace inaf::oasbo::PacketMonitors {
Valerio Pastore's avatar
Valerio Pastore committed
/**
 * @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.
 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
class BasePacketMonitor {
Valerio Pastore's avatar
Valerio Pastore committed
protected:
Valerio Pastore's avatar
Valerio Pastore committed
	std::map<std::string, std::string> stats; /**< A map to store statistics related to the monitored packets. */
Valerio Pastore's avatar
Valerio Pastore committed
public:
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @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.
	 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
	virtual void monit(Packets::BasePacket &packet) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @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.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	virtual void reset() = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @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.
	 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
	virtual std::map<std::string, std::string> getStatsMap() const {
		return stats;
	}
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
.  
Valerio Pastore committed
	/**
	 * @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 {
Valerio Pastore's avatar
Valerio Pastore committed
		try {
			return this->stats.at(stat);
Valerio Pastore's avatar
.  
Valerio Pastore committed
		} catch (const std::out_of_range&) {
Valerio Pastore's avatar
Valerio Pastore committed
			return std::nullopt;
		}
Valerio Pastore's avatar
.  
Valerio Pastore committed
	}
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Default destructor.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	virtual ~BasePacketMonitor() = default;
Valerio Pastore's avatar
Valerio Pastore committed
};
Valerio Pastore's avatar
Valerio Pastore committed
}