|
| 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 DETECTOR_GRPDCSDPSPROCESSOR_H_ |
| 13 | +#define DETECTOR_GRPDCSDPSPROCESSOR_H_ |
| 14 | + |
| 15 | +#include <Rtypes.h> |
| 16 | +#include <unordered_map> |
| 17 | +#include <deque> |
| 18 | +#include "Framework/Logger.h" |
| 19 | +#include "DetectorsDCS/DataPointCompositeObject.h" |
| 20 | +#include "DetectorsDCS/DataPointIdentifier.h" |
| 21 | +#include "DetectorsDCS/DataPointValue.h" |
| 22 | +#include "DetectorsDCS/DeliveryType.h" |
| 23 | +#include "CCDB/CcdbObjectInfo.h" |
| 24 | +#include "CommonUtils/MemFileHelper.h" |
| 25 | +#include "CCDB/CcdbApi.h" |
| 26 | +#include "DataFormatsParameters/GRPMagField.h" |
| 27 | +#include <gsl/gsl> |
| 28 | + |
| 29 | +/// @brief Class to process GRP DCS data points (B field, environment variables, LHCIF Data Points) |
| 30 | + |
| 31 | +namespace o2 |
| 32 | +{ |
| 33 | +namespace grp |
| 34 | +{ |
| 35 | + |
| 36 | +using DPID = o2::dcs::DataPointIdentifier; |
| 37 | +using DPVAL = o2::dcs::DataPointValue; |
| 38 | +using DPCOM = o2::dcs::DataPointCompositeObject; |
| 39 | + |
| 40 | +struct GRPEnvVariables { |
| 41 | + |
| 42 | + std::pair<uint64_t, double> mCavernTemperature; |
| 43 | + std::pair<uint64_t, double> mCavernAtmosPressure; |
| 44 | + std::pair<uint64_t, double> mSurfaceAtmosPressure; |
| 45 | + std::pair<uint64_t, double> mCavernAtmosPressure2; |
| 46 | + |
| 47 | + GRPEnvVariables() |
| 48 | + { |
| 49 | + mCavernTemperature = std::make_pair(0, -999999999); |
| 50 | + mCavernAtmosPressure = std::make_pair(0, -999999999); |
| 51 | + mSurfaceAtmosPressure = std::make_pair(0, -999999999); |
| 52 | + mCavernAtmosPressure2 = std::make_pair(0, -999999999); |
| 53 | + } |
| 54 | + |
| 55 | + void print() |
| 56 | + { |
| 57 | + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Temperature", mCavernTemperature.first, mCavernTemperature.second); |
| 58 | + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Atm Pressure", mCavernAtmosPressure.first, mCavernAtmosPressure.second); |
| 59 | + std::printf("%-30s : timestamp %llu val %.3f\n", "Surf Atm Pressure", mSurfaceAtmosPressure.first, mSurfaceAtmosPressure.second); |
| 60 | + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Atm Pressure 2", mCavernAtmosPressure2.first, mCavernAtmosPressure2.second); |
| 61 | + } |
| 62 | + |
| 63 | + ClassDefNV(GRPEnvVariables, 1); |
| 64 | +}; |
| 65 | + |
| 66 | +struct GRPCollimators { |
| 67 | + |
| 68 | + std::pair<uint64_t, double> mgap_downstream; |
| 69 | + std::pair<uint64_t, double> mgap_upstream; |
| 70 | + std::pair<uint64_t, double> mleft_downstream; |
| 71 | + std::pair<uint64_t, double> mleft_upstream; |
| 72 | + std::pair<uint64_t, double> mright_downstream; |
| 73 | + std::pair<uint64_t, double> mright_upstream; |
| 74 | + |
| 75 | + GRPCollimators() |
| 76 | + { |
| 77 | + mgap_downstream = std::make_pair(0, -999999999); |
| 78 | + mgap_upstream = std::make_pair(0, -999999999); |
| 79 | + mleft_downstream = std::make_pair(0, -999999999); |
| 80 | + mleft_upstream = std::make_pair(0, -999999999); |
| 81 | + mright_downstream = std::make_pair(0, -999999999); |
| 82 | + mright_upstream = std::make_pair(0, -999999999); |
| 83 | + } |
| 84 | + |
| 85 | + void print() |
| 86 | + { |
| 87 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", mgap_downstream.first, mgap_downstream.second); |
| 88 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream", mgap_upstream.first, mgap_upstream.second); |
| 89 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", mleft_downstream.first, mleft_downstream.second); |
| 90 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream", mleft_upstream.first, mleft_upstream.second); |
| 91 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", mright_downstream.first, mright_downstream.second); |
| 92 | + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream", mright_upstream.first, mright_upstream.second); |
| 93 | + } |
| 94 | + |
| 95 | + ClassDefNV(GRPCollimators, 1); |
| 96 | +}; |
| 97 | + |
| 98 | +struct GRPLHCInfo { |
| 99 | + |
| 100 | + std::array<std::vector<std::pair<uint64_t, double>>, 2> mIntensityBeam; |
| 101 | + std::array<std::vector<std::pair<uint64_t, double>>, 3> mBackground; |
| 102 | + std::vector<std::pair<uint64_t, double>> mInstLumi; |
| 103 | + std::vector<std::pair<uint64_t, double>> mBPTXdeltaT; |
| 104 | + std::vector<std::pair<uint64_t, double>> mBPTXdeltaTRMS; |
| 105 | + std::array<std::vector<std::pair<uint64_t, double>>, 2> mBPTXPhase; |
| 106 | + std::array<std::vector<std::pair<uint64_t, double>>, 2> mBPTXPhaseRMS; |
| 107 | + std::array<std::vector<std::pair<uint64_t, double>>, 2> mBPTXPhaseShift; |
| 108 | + std::pair<uint64_t, std::string> mLumiSource; // only one value per object: when there is a change, a new object is stored |
| 109 | + std::pair<uint64_t, std::string> mMachineMode; // only one value per object: when there is a change, a new object is stored |
| 110 | + std::pair<uint64_t, std::string> mBeamMode; // only one value per object: when there is a change, a new object is stored |
| 111 | + |
| 112 | + void reset() |
| 113 | + { |
| 114 | + for (int i = 0; i < 2; ++i) { |
| 115 | + mIntensityBeam[i].clear(); |
| 116 | + mBPTXPhase[i].clear(); |
| 117 | + mBPTXPhaseRMS[i].clear(); |
| 118 | + mBPTXPhaseShift[i].clear(); |
| 119 | + } |
| 120 | + for (int i = 0; i < 3; ++i) { |
| 121 | + mBackground[i].clear(); |
| 122 | + } |
| 123 | + mInstLumi.clear(); |
| 124 | + mBPTXdeltaT.clear(); |
| 125 | + mBPTXdeltaTRMS.clear(); |
| 126 | + } |
| 127 | + |
| 128 | + void print() |
| 129 | + { |
| 130 | + char alias[60]; |
| 131 | + for (int i = 0; i < 2; ++i) { |
| 132 | + std::sprintf(alias, "LHC_IntensityBeam%d_totalIntensity", i + 1); |
| 133 | + std::printf("%-30s : n elements %ld\n", alias, mIntensityBeam[i].size()); |
| 134 | + for (int iel = 0; iel < mIntensityBeam[i].size(); ++iel) { |
| 135 | + std::printf("timestamp %llu val %.3e\n", mIntensityBeam[i].at(iel).first, mIntensityBeam[i].at(iel).second); |
| 136 | + } |
| 137 | + } |
| 138 | + for (int i = 0; i < 3; ++i) { |
| 139 | + std::sprintf(alias, "ALI_Background%d", i + 1); |
| 140 | + std::printf("%-30s : n elements %ld\n", alias, mBackground[i].size()); |
| 141 | + for (int iel = 0; iel < mBackground[i].size(); ++iel) { |
| 142 | + std::printf("timestamp %llu val %.3e\n", mBackground[i].at(iel).first, mBackground[i].at(iel).second); |
| 143 | + } |
| 144 | + } |
| 145 | + std::printf("%-30s : n elements %ld\n", "ALI_Lumi_Total_Inst", mInstLumi.size()); |
| 146 | + for (int iel = 0; iel < mInstLumi.size(); ++iel) { |
| 147 | + std::printf("timestamp %llu val %.3e\n", mInstLumi.at(iel).first, mInstLumi.at(iel).second); |
| 148 | + } |
| 149 | + std::printf("%-30s : n elements %ld\n", "BPTX_deltaT_B1_B2", mBPTXdeltaT.size()); |
| 150 | + for (int iel = 0; iel < mBPTXdeltaT.size(); ++iel) { |
| 151 | + std::printf("timestamp %llu val %.3e\n", mBPTXdeltaT.at(iel).first, mBPTXdeltaT.at(iel).second); |
| 152 | + } |
| 153 | + std::printf("%-30s : n elements %ld\n", "BPTX_deltaTRMS_B1_B2", mBPTXdeltaTRMS.size()); |
| 154 | + for (int iel = 0; iel < mBPTXdeltaTRMS.size(); ++iel) { |
| 155 | + std::printf("timestamp %llu val %.3e\n", mBPTXdeltaTRMS.at(iel).first, mBPTXdeltaTRMS.at(iel).second); |
| 156 | + } |
| 157 | + for (int i = 0; i < 2; ++i) { |
| 158 | + std::sprintf(alias, "BPTX_Phase_B%d", i + 1); |
| 159 | + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhase[i].size()); |
| 160 | + for (int iel = 0; iel < mBPTXPhase[i].size(); ++iel) { |
| 161 | + std::printf("timestamp %llu val %.3e\n", mBPTXPhase[i].at(iel).first, mBPTXPhase[i].at(iel).second); |
| 162 | + } |
| 163 | + } |
| 164 | + for (int i = 0; i < 2; ++i) { |
| 165 | + std::sprintf(alias, "BPTX_PhaseRMS_B%d", i + 1); |
| 166 | + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhaseRMS[i].size()); |
| 167 | + for (int iel = 0; iel < mBPTXPhaseRMS[i].size(); ++iel) { |
| 168 | + std::printf("timestamp %llu val %.3e\n", mBPTXPhaseRMS[i].at(iel).first, mBPTXPhaseRMS[i].at(iel).second); |
| 169 | + } |
| 170 | + } |
| 171 | + for (int i = 0; i < 2; ++i) { |
| 172 | + std::sprintf(alias, "BPTX_Phase_Shift_B%d", i + 1); |
| 173 | + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhaseShift[i].size()); |
| 174 | + for (int iel = 0; iel < mBPTXPhaseShift[i].size(); ++iel) { |
| 175 | + std::printf("timestamp %llu val %.3e\n", mBPTXPhaseShift[i].at(iel).first, mBPTXPhaseShift[i].at(iel).second); |
| 176 | + } |
| 177 | + } |
| 178 | + std::printf("%-30s :\n", "ALI_Lumi_Source_Name"); |
| 179 | + std::printf("timestamp %llu val %s\n", mLumiSource.first, mLumiSource.second.c_str()); |
| 180 | + std::printf("%-30s :\n", "BEAM_MODE"); |
| 181 | + std::printf("timestamp %llu val %s\n", mBeamMode.first, mBeamMode.second.c_str()); |
| 182 | + std::printf("%-30s :\n", "MACHINE_MODE"); |
| 183 | + std::printf("timestamp %llu val %s\n", mMachineMode.first, mMachineMode.second.c_str()); |
| 184 | + } |
| 185 | + |
| 186 | + ClassDefNV(GRPLHCInfo, 1); |
| 187 | +}; |
| 188 | + |
| 189 | +class GRPDCSDPsProcessor |
| 190 | +{ |
| 191 | + public: |
| 192 | + GRPDCSDPsProcessor() = default; |
| 193 | + ~GRPDCSDPsProcessor() = default; |
| 194 | + |
| 195 | + void init(const std::vector<DPID>& pids); |
| 196 | + int process(const gsl::span<const DPCOM> dps); |
| 197 | + int processDP(const DPCOM& dpcom); |
| 198 | + uint64_t processFlags(uint64_t flag, const char* pid) { return 0; } // for now it is not really implemented |
| 199 | + void processCollimators(const DPCOM& dpcom); |
| 200 | + void processEnvVar(const DPCOM& dpcom); |
| 201 | + void processPair(const DPCOM& dpcom, const std::string& alias, std::pair<uint64_t, double>& p, bool& flag); |
| 202 | + bool compareAndUpdate(std::pair<uint64_t, double>& p, const DPCOM& dpcom); |
| 203 | + bool processLHCIFDPs(const DPCOM& dpcom); |
| 204 | + |
| 205 | + void resetLHCIFDPs() { mLHCInfo.reset(); } |
| 206 | + |
| 207 | + const o2::parameters::GRPMagField& getMagFieldObj() const { return mMagField; } |
| 208 | + const o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() const { return mccdbMagFieldInfo; } |
| 209 | + o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() { return mccdbMagFieldInfo; } |
| 210 | + void updateMagFieldCCDB(); |
| 211 | + bool isMagFieldUpdated() const { return mUpdateMagField; } |
| 212 | + |
| 213 | + const GRPLHCInfo& getLHCIFObj() const { return mLHCInfo; } |
| 214 | + const o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() const { return mccdbLHCIFInfo; } |
| 215 | + o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() { return mccdbLHCIFInfo; } |
| 216 | + void updateLHCIFInfoCCDB(); |
| 217 | + bool isLHCIFInfoUpdated() const { return mUpdateLHCIFInfo; } |
| 218 | + |
| 219 | + const GRPEnvVariables& getEnvVarsObj() const { return mEnvVars; } |
| 220 | + const o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() const { return mccdbEnvVarsInfo; } |
| 221 | + o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() { return mccdbEnvVarsInfo; } |
| 222 | + void updateEnvVarsCCDB(); |
| 223 | + bool isEnvVarsUpdated() const { return mUpdateEnvVars; } |
| 224 | + |
| 225 | + const GRPCollimators& getCollimatorsObj() const { return mCollimators; } |
| 226 | + const o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() const { return mccdbCollimatorsInfo; } |
| 227 | + o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() { return mccdbCollimatorsInfo; } |
| 228 | + void updateCollimatorsCCDB(); |
| 229 | + bool isCollimatorsUpdated() const { return mUpdateCollimators; } |
| 230 | + |
| 231 | + void setStartValidity(long t) { mStartValidity = t; } |
| 232 | + void useVerboseMode() { mVerbose = true; } |
| 233 | + |
| 234 | + private: |
| 235 | + std::unordered_map<DPID, bool> mPids; // contains all PIDs for the processor, the bool |
| 236 | + // will be true if the DP was processed at least once |
| 237 | + |
| 238 | + long mFirstTime; // time when a CCDB object was stored first |
| 239 | + long mStartValidity = 0; // TF index for processing, used to store CCDB object |
| 240 | + bool mFirstTimeSet = false; |
| 241 | + |
| 242 | + bool mVerbose = false; |
| 243 | + |
| 244 | + o2::parameters::GRPMagField mMagField; |
| 245 | + o2::ccdb::CcdbObjectInfo mccdbMagFieldInfo; |
| 246 | + bool mUpdateMagField = false; |
| 247 | + |
| 248 | + GRPEnvVariables mEnvVars; |
| 249 | + o2::ccdb::CcdbObjectInfo mccdbEnvVarsInfo; |
| 250 | + bool mUpdateEnvVars = false; |
| 251 | + |
| 252 | + GRPCollimators mCollimators; |
| 253 | + o2::ccdb::CcdbObjectInfo mccdbCollimatorsInfo; |
| 254 | + bool mUpdateCollimators = false; |
| 255 | + |
| 256 | + GRPLHCInfo mLHCInfo; |
| 257 | + o2::ccdb::CcdbObjectInfo mccdbLHCIFInfo; |
| 258 | + bool mUpdateLHCIFInfo = false; |
| 259 | + |
| 260 | + ClassDefNV(GRPDCSDPsProcessor, 0); |
| 261 | +}; |
| 262 | +} // namespace grp |
| 263 | +} // namespace o2 |
| 264 | + |
| 265 | +#endif |
0 commit comments