|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +#ifndef ZDC_NOISECALIB_DATA_H |
| 13 | +#define ZDC_NOISECALIB_DATA_H |
| 14 | + |
| 15 | +#include "Framework/Logger.h" |
| 16 | +#include "ZDCBase/Constants.h" |
| 17 | +#include <array> |
| 18 | +#include <vector> |
| 19 | +#include <map> |
| 20 | +#include <gsl/span> |
| 21 | + |
| 22 | +/// \file NoiseCalibData.h |
| 23 | +/// \brief Format of noise calibration intermediate data |
| 24 | +/// \author pietro.cortese@cern.ch |
| 25 | + |
| 26 | +namespace o2 |
| 27 | +{ |
| 28 | +namespace zdc |
| 29 | +{ |
| 30 | + |
| 31 | +// Messageable representation of noise calibration data |
| 32 | +struct NoiseCalibBinData { |
| 33 | + NoiseCalibBinData() = default; |
| 34 | + NoiseCalibBinData(uint8_t myid, uint32_t myibin, uint32_t mycont) |
| 35 | + { |
| 36 | + ibin = (myid << 24) | (myibin & 0x00ffffff); |
| 37 | + cont = mycont; |
| 38 | + } |
| 39 | + uint32_t ibin = 0xff000000; /// Encoded channel ID / bin number |
| 40 | + uint32_t cont = 0; /// Channel counts |
| 41 | + inline uint32_t id() const |
| 42 | + { // Channel id |
| 43 | + return (ibin >> 24); |
| 44 | + } |
| 45 | + inline uint32_t bin() const |
| 46 | + { // Bin number |
| 47 | + return (ibin & 0x00ffffff); |
| 48 | + } |
| 49 | + inline uint32_t counts() const |
| 50 | + { // Channel counts |
| 51 | + return cont; |
| 52 | + } |
| 53 | + void print() const |
| 54 | + { |
| 55 | + LOGF(info, "NoiseCalibBinData ch=%2u bin=%4u cont=%u", id(), bin(), counts()); |
| 56 | + } |
| 57 | + ClassDefNV(NoiseCalibBinData, 1); |
| 58 | +}; |
| 59 | + |
| 60 | +// Container of the messageable representation of noise calibration data |
| 61 | +struct NoiseCalibSummaryData { |
| 62 | + NoiseCalibSummaryData() = default; |
| 63 | + uint64_t mCTimeBeg = 0; /// Time of processed time frame |
| 64 | + uint64_t mCTimeEnd = 0; /// Time of processed time frame |
| 65 | + bool mOverflow = false; /// Overflow of one channel |
| 66 | + std::array<bool, NChannels> mOverflowCh{}; /// Channel overflow information |
| 67 | + std::vector<NoiseCalibBinData> mData; /// Data of not empty bins |
| 68 | + void clear(); |
| 69 | + void print() const; |
| 70 | + ClassDefNV(NoiseCalibSummaryData, 1); |
| 71 | +}; |
| 72 | + |
| 73 | +// Working representation of noise channel data |
| 74 | +struct NoiseCalibChData { |
| 75 | + NoiseCalibChData() = default; |
| 76 | + // Variance intermediate data are uint32_t and sparse (~25% channels are filled) |
| 77 | + // and histogram limits are not known in advance -> use map |
| 78 | + std::map<uint32_t, uint32_t> mData; /// Map histogram container |
| 79 | + bool mOverflow = false; /// Overflow flag (cannot accept more data) |
| 80 | + uint64_t getEntries() const; |
| 81 | + uint32_t getMaxBin() const; |
| 82 | + int getStat(uint64_t& en, double& mean, double& var) const; |
| 83 | + inline bool isOverflow() { return mOverflow; }; |
| 84 | + void clear(); |
| 85 | + ClassDefNV(NoiseCalibChData, 1); |
| 86 | +}; |
| 87 | + |
| 88 | +// Working representation of noise data |
| 89 | +struct NoiseCalibData { |
| 90 | + NoiseCalibData() = default; |
| 91 | + |
| 92 | + uint64_t mCTimeBeg = 0; /// Time of processed time frame |
| 93 | + uint64_t mCTimeEnd = 0; /// Time of processed time frame |
| 94 | + bool mOverflow = false; /// Overflow at least one ZDC channel |
| 95 | + |
| 96 | + NoiseCalibChData mHisto[NChannels]; /// Sparse histogram of single channels |
| 97 | + NoiseCalibSummaryData mSummary; /// Serialized data to be dispatched |
| 98 | + |
| 99 | + NoiseCalibData& operator+=(const NoiseCalibData& other); |
| 100 | + NoiseCalibData& operator=(const NoiseCalibSummaryData& s); |
| 101 | + // NoiseCalibData& operator+=(const NoiseCalibSummaryData& s); |
| 102 | + NoiseCalibData& operator+=(const NoiseCalibSummaryData* s); |
| 103 | + |
| 104 | + inline void addEntry(int isig, uint32_t val) |
| 105 | + { |
| 106 | + if (!mHisto[isig].mOverflow) { |
| 107 | + int ibin = 0x00ffffff; |
| 108 | + // Overflow in bin number |
| 109 | + if (val < 0x00ffffff) { |
| 110 | + ibin = val; |
| 111 | + } |
| 112 | + // Overflow in data |
| 113 | + if (mHisto[isig].mData[ibin] < 0xffffffff) { |
| 114 | + mHisto[isig].mData[ibin]++; |
| 115 | + } else { |
| 116 | + mHisto[isig].mOverflow = true; |
| 117 | + mOverflow = true; |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + uint64_t getEntries(int is) const; |
| 123 | + uint32_t getMaxBin(int is) const; |
| 124 | + int getStat(int is, uint64_t& en, double& mean, double& var) const; |
| 125 | + void print() const; |
| 126 | + void clear(); |
| 127 | + void setCreationTime(uint64_t ctime); |
| 128 | + void setN(int n); |
| 129 | + NoiseCalibSummaryData& getSummary(); |
| 130 | + int saveDebugHistos(const std::string fn); |
| 131 | + ClassDefNV(NoiseCalibData, 1); |
| 132 | +}; |
| 133 | + |
| 134 | +} // namespace zdc |
| 135 | +} // namespace o2 |
| 136 | + |
| 137 | +#endif |
0 commit comments