#ifndef __JDAQSUMMARYFRAME__ #define __JDAQSUMMARYFRAME__ #include #include #include "JDAQ/JDAQException.hh" #include "JDAQ/JDAQ.hh" #include "JDAQ/JDAQModuleIdentifier.hh" namespace KM3NETDAQ { /** * Forward declaration for friend declaration of JDAQSummaryFrame inside JDAQRate. */ class JDAQSummaryFrame; /** * Data storage class for rate measurement of one PMT. */ class JDAQRate { public: friend class JDAQSummaryFrame; typedef unsigned char JRate_t; // type of value to store rate static const double MINIMAL_RATE_HZ = 2.0e3; // minimal rate (below this, value is set to zero) static const double MAXIMAL_RATE_HZ = 2.0e6; // maximal rate (above this, value is set to maximum) /** * Get value. * * \param numberOfHits number of hits * \param frameTime_ns frame time [ns] * \return value */ static JRate_t getValue(const int numberOfHits, const double frameTime_ns) { return getValue(numberOfHits * 1.0e9 / frameTime_ns); } /** * Get value. * * \param rate_Hz rate [Hz] * \return value */ static JRate_t getValue(const double rate_Hz) { if (rate_Hz <= MINIMAL_RATE_HZ) return 0; else if (rate_Hz >= MAXIMAL_RATE_HZ) return std::numeric_limits::max(); else return (JRate_t) (log(rate_Hz/MINIMAL_RATE_HZ) / getFactor() + 0.5); } /** * Get count rate. * * \param value value * \return rate [Hz] */ static double getRate(const JRate_t value) { if (value == 0) return 0.0; else return MINIMAL_RATE_HZ * std::exp(value * getFactor()); } /** * Default constructor. */ JDAQRate() : value(0) {} /** * Get value. * * \return value */ JRate_t getValue() const { return value; } /** * Set value. * * \param numberOfHits number of hits * \param frameTime_ns frame time [ns] */ void setValue(const int numberOfHits, const double frameTime_ns) { value = getValue(numberOfHits, frameTime_ns); } /** * Set value. * * \param rate_Hz rate [Hz] */ void setValue(const double rate_Hz) { value = getValue(rate_Hz); } /** * Get count rate. * * \return rate [Hz] */ double getRate() const { return getRate(value); } protected: JRate_t value; private: /** * Get conversion factor. * * \return factor */ static const double getFactor() { return std::log(MAXIMAL_RATE_HZ / MINIMAL_RATE_HZ) / std::numeric_limits::max(); } }; /** * Data storage class for rate measurements of all PMTs in one module. */ class JDAQSummaryFrame : public JDAQModuleIdentifier { public: typedef JDAQRate::JRate_t JRate_t; /** * Default constructor. */ JDAQSummaryFrame() : JDAQModuleIdentifier() {} /** * Constructor. * * \param moduleID module identifier */ JDAQSummaryFrame(const int moduleID) : JDAQModuleIdentifier(moduleID) {} /** * Get DAQ rate of given PMT. * * \param address PMT address [0-31] * \return JDAQRate */ const JDAQRate& operator[](const int address) const { if (address >= 0 && address < NUMBER_OF_PMTS) return data[address]; else throw JDAQException("PMT address out of range."); } /** * Get DAQ rate of given PMT. * * \param address PMT address [0-31] * \return JDAQRate */ JDAQRate& operator[](const int address) { if (address >= 0 && address < NUMBER_OF_PMTS) return data[address]; else throw JDAQException("PMT address out of range."); } /** * Get count rate. * * \param address PMT address [0-31] * \return rate [Hz] */ double getRate(const int address) const { return (*this)[address].getRate(); } /** * Read DAQ summary frame from input. * * \param in JReader * \param summary JDAQSummaryFrame * \return JReader */ friend inline JReader& operator>>(JReader& in, JDAQSummaryFrame& summary) { in >> static_cast(summary); in.read((char*) summary.data, NUMBER_OF_PMTS * sizeof(JRate_t)); return in; } /** * Write DAQ summary frame to output. * * \param out JWriter * \param summary DAQSummaryFrame * \return JWriter */ friend inline JWriter& operator<<(JWriter& out, const JDAQSummaryFrame& summary) { out << static_cast(summary); out.write((char*) summary.data, NUMBER_OF_PMTS * sizeof(JRate_t)); return out; } /** * Get size of object. * * \return number of bytes */ static int sizeOf() { return (JDAQModuleIdentifier::sizeOf() + NUMBER_OF_PMTS * sizeof(JDAQRate)); } ClassDefNV(JDAQSummaryFrame,1); protected: JDAQRate data[NUMBER_OF_PMTS]; }; } #endif