Project
Loading...
Searching...
No Matches
GRPDCSDPsProcessor.h
Go to the documentation of this file.
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 "Framework/O2LongInt.h"
24#include "CCDB/CcdbObjectInfo.h"
26#include "CCDB/CcdbApi.h"
28#include <gsl/gsl>
29
31
32namespace o2
33{
34namespace grp
35{
36
40
41inline O2LongUInt llu2lu(std::uint64_t v) { return (O2LongUInt)v; }
42
44
45 std::unordered_map<std::string, std::vector<std::pair<O2LongUInt, double>>> mEnvVars;
46 size_t totalEntries() const
47 {
48 size_t s = 0;
49 for (const auto& el : mEnvVars) {
50 s += el.second.size();
51 }
52 return s;
53 }
54 void print()
55 {
56 for (const auto& el : mEnvVars) {
57 std::printf("%-30s\n", el.first.c_str());
58 for (const auto& it : el.second) {
59 std::printf("timestamp %lu val %.3f\n", llu2lu(it.first), it.second);
60 }
61 }
62 }
63
65};
66
68 int isSet = 0;
69 float curL3 = 0.;
70 float curDip = 0.;
71 bool negL3 = 0;
72 bool negDip = 0;
73 bool updated = false;
74 bool verbose = false;
75 static constexpr float ZeroCurrent = 70.f; // current below this threshold considered to be produce 0 field
76 static constexpr float DeltaThreshold = 0.2f; // update field on delta's exceeding this value
77
78 void updateCurL3(float v)
79 {
80 if (!(isSet & 0x1) || (std::abs(v - curL3) > DeltaThreshold && (std::abs(v) > ZeroCurrent || std::abs(curL3) > ZeroCurrent))) {
81 if (verbose) {
82 LOG(info) << "L3 current will be updated from " << curL3 << " to " << v;
83 }
84 curL3 = v;
85 isSet |= 0x1;
86 updated = true;
87 }
88 }
89 void updateCurDip(float v)
90 {
91 if (!(isSet & 0x2) || (std::abs(v - curDip) > DeltaThreshold && (std::abs(v) > ZeroCurrent || std::abs(curDip) > ZeroCurrent))) {
92 if (verbose) {
93 LOG(info) << "Dipole current will be updated from " << curDip << " to " << v;
94 }
95 curDip = v;
96 isSet |= 0x2;
97 updated = true;
98 }
99 }
100 void updateSignL3(bool v)
101 {
102 if (!(isSet & 0x4) || v != negL3) {
103 if (verbose) {
104 LOG(info) << "L3 polarity will be updated from " << negL3 << " to " << v;
105 }
106 negL3 = v;
107 isSet |= 0x4;
108 updated = true;
109 }
110 }
111 void updateSignDip(bool v)
112 {
113 if (!(isSet & 0x8) || v != negDip) {
114 if (verbose) {
115 LOG(info) << "Dipole polarity will be updated from " << negDip << " to " << v;
116 }
117 negDip = v;
118 isSet |= 0x8;
119 updated = true;
120 }
121 }
122};
123
125
126 std::unordered_map<std::string, std::vector<std::pair<O2LongUInt, double>>> mCollimators;
127 size_t totalEntries() const
128 {
129 size_t s = 0;
130 for (const auto& el : mCollimators) {
131 s += el.second.size();
132 }
133 return s;
134 }
135 void print()
136 {
137 for (const auto& el : mCollimators) {
138 std::printf("%-60s\n", el.first.c_str());
139 for (const auto& it : el.second) {
140 std::printf("timestamp %lu val %.3f\n", llu2lu(it.first), it.second);
141 }
142 }
143 }
144
146};
147
149
182 static constexpr std::string_view collimatorAliases[NCollimatorAliases] = {"LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream",
183 "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream",
184 "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream"};
185 static constexpr std::string_view beamAliases[NBeamAliases] = {"LHC_IntensityBeam1_totalIntensity", "LHC_IntensityBeam2_totalIntensity"};
186 static constexpr std::string_view bkgAliases[NBkgAliases] = {"ALI_Background1", "ALI_Background2", "ALI_Background3"};
187 static constexpr std::string_view bptxAliases[NBPTXAliases] = {"BPTX_deltaT_B1_B2", "BPTX_deltaTRMS_B1_B2"};
188 static constexpr std::string_view bptxPhaseAliases[NBPTXPhaseAliases] = {"BPTX_Phase_B1", "BPTX_Phase_B2"};
189 static constexpr std::string_view bptxPhaseRMSAliases[NBPTXPhaseRMSAliases] = {"BPTX_PhaseRMS_B1", "BPTX_PhaseRMS_B2"};
190 static constexpr std::string_view bptxPhaseShiftAliases[NBPTXPhaseShiftAliases] = {"BPTX_Phase_Shift_B1", "BPTX_Phase_Shift_B2"};
191 static constexpr std::string_view lumiAliases[NLumiAliases] = {"ALI_Lumi_Total_Inst"};
192 static constexpr std::string_view lhcStringAliases[NLHCStringAliases] = {"ALI_Lumi_Source_Name", "BEAM_MODE", "MACHINE_MODE"};
194
195 std::array<std::vector<std::pair<O2LongUInt, double>>, 2> mIntensityBeam;
196 std::array<std::vector<std::pair<O2LongUInt, double>>, 3> mBackground;
197 std::vector<std::pair<O2LongUInt, double>> mInstLumi;
198 std::vector<std::pair<O2LongUInt, double>> mBPTXdeltaT;
199 std::vector<std::pair<O2LongUInt, double>> mBPTXdeltaTRMS;
200 std::array<std::vector<std::pair<O2LongUInt, double>>, 2> mBPTXPhase;
201 std::array<std::vector<std::pair<O2LongUInt, double>>, 2> mBPTXPhaseRMS;
202 std::array<std::vector<std::pair<O2LongUInt, double>>, 2> mBPTXPhaseShift;
203 std::pair<O2LongUInt, std::string> mLumiSource; // only one value per object: when there is a change, a new object is stored
204 std::pair<O2LongUInt, std::string> mMachineMode; // only one value per object: when there is a change, a new object is stored
205 std::pair<O2LongUInt, std::string> mBeamMode; // only one value per object: when there is a change, a new object is stored
206
207 void resetAndKeepLastVector(std::vector<std::pair<O2LongUInt, double>>& vect)
208 {
209 // always check that the size is > 0 (--> begin != end) for all vectors
210 if (vect.begin() != vect.end()) {
211 vect.erase(vect.begin(), vect.end() - 1);
212 }
213 }
214
230
231 void print()
232 {
233 for (int i = 0; i < NBeamAliases; ++i) {
234 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(beamAliases[i]).c_str(), mIntensityBeam[i].size());
235 for (int iel = 0; iel < mIntensityBeam[i].size(); ++iel) {
236 std::printf("timestamp %lu val %.3e\n", llu2lu(mIntensityBeam[i].at(iel).first), mIntensityBeam[i].at(iel).second);
237 }
238 }
239 for (int i = 0; i < NBkgAliases; ++i) {
240 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bkgAliases[i]).c_str(), mBackground[i].size());
241 for (int iel = 0; iel < mBackground[i].size(); ++iel) {
242 std::printf("timestamp %lu val %.3e\n", llu2lu(mBackground[i].at(iel).first), mBackground[i].at(iel).second);
243 }
244 }
245 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(lumiAliases[ALI_Lumi_Total_Inst]).c_str(), mInstLumi.size());
246 for (int iel = 0; iel < mInstLumi.size(); ++iel) {
247 std::printf("timestamp %lu val %.3e\n", llu2lu(mInstLumi.at(iel).first), mInstLumi.at(iel).second);
248 }
249 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bptxAliases[BPTX_deltaT_B1_B2]).c_str(), mBPTXdeltaT.size());
250 for (int iel = 0; iel < mBPTXdeltaT.size(); ++iel) {
251 std::printf("timestamp %lu val %.3e\n", llu2lu(mBPTXdeltaT.at(iel).first), mBPTXdeltaT.at(iel).second);
252 }
253 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bptxAliases[BPTX_deltaTRMS_B1_B2]).c_str(), mBPTXdeltaTRMS.size());
254 for (int iel = 0; iel < mBPTXdeltaTRMS.size(); ++iel) {
255 std::printf("timestamp %lu val %.3e\n", llu2lu(mBPTXdeltaTRMS.at(iel).first), mBPTXdeltaTRMS.at(iel).second);
256 }
257 for (int i = 0; i < NBPTXPhaseAliases; ++i) {
258 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bptxPhaseAliases[i]).c_str(), mBPTXPhase[i].size());
259 for (int iel = 0; iel < mBPTXPhase[i].size(); ++iel) {
260 std::printf("timestamp %lu val %.3e\n", llu2lu(mBPTXPhase[i].at(iel).first), mBPTXPhase[i].at(iel).second);
261 }
262 }
263 for (int i = 0; i < NBPTXPhaseRMSAliases; ++i) {
264 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bptxPhaseRMSAliases[i]).c_str(), mBPTXPhaseRMS[i].size());
265 for (int iel = 0; iel < mBPTXPhaseRMS[i].size(); ++iel) {
266 std::printf("timestamp %lu val %.3e\n", llu2lu(mBPTXPhaseRMS[i].at(iel).first), mBPTXPhaseRMS[i].at(iel).second);
267 }
268 }
269 for (int i = 0; i < NBPTXPhaseShiftAliases; ++i) {
270 std::printf("%-30s : n elements %ld\n", static_cast<std::string>(bptxPhaseShiftAliases[i]).c_str(), mBPTXPhaseShift[i].size());
271 for (int iel = 0; iel < mBPTXPhaseShift[i].size(); ++iel) {
272 std::printf("timestamp %lu val %.3e\n", llu2lu(mBPTXPhaseShift[i].at(iel).first), mBPTXPhaseShift[i].at(iel).second);
273 }
274 }
275 std::printf("%-30s :\n", static_cast<std::string>(lhcStringAliases[ALI_Lumi_Source_Name]).c_str());
276 std::printf("timestamp %lu val %s\n", llu2lu(mLumiSource.first), mLumiSource.second.c_str());
277 std::printf("%-30s :\n", static_cast<std::string>(lhcStringAliases[BEAM_MODE]).c_str());
278 std::printf("timestamp %lu val %s\n", llu2lu(mBeamMode.first), mBeamMode.second.c_str());
279 std::printf("%-30s :\n", static_cast<std::string>(lhcStringAliases[MACHINE_MODE]).c_str());
280 std::printf("timestamp %lu val %s\n", llu2lu(mMachineMode.first), mMachineMode.second.c_str());
281 }
282
284};
285
287{
288 public:
291
292 void init(const std::vector<DPID>& pids);
293 int process(const gsl::span<const DPCOM> dps);
294 int processDP(const DPCOM& dpcom);
295 O2LongUInt processFlags(O2LongUInt flag, const char* pid) { return 0; } // for now it is not really implemented
296 bool processCollimators(const DPCOM& dpcom);
297 bool processEnvVar(const DPCOM& dpcom);
298 bool processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map<std::string, std::vector<std::pair<O2LongUInt, double>>>& mapToUpdate);
299 bool processPairS(const DPCOM& dpcom, const std::string& alias, std::pair<O2LongUInt, std::string>& p, bool& flag);
300 bool compareToLatest(std::pair<O2LongUInt, double>& p, double val);
301 bool processLHCIFDPs(const DPCOM& dpcom);
302
304 void resetAndKeepLast(std::unordered_map<std::string, std::vector<std::pair<O2LongUInt, double>>>& mapToReset)
305 {
306 // keep only the latest measurement
307 for (auto& el : mapToReset) {
308 if (el.second.begin() != el.second.end()) {
309 el.second.erase(el.second.begin(), el.second.end() - 1);
310 }
311 }
312 }
313
315 {
316 for (auto& it : mPids) {
317 it.second = false;
318 }
319 }
320
322 {
323 for (auto& it : mPids) {
324 for (const auto& iArray : mArrLHCAliases) {
325 if (it.first.get_alias() == static_cast<std::string>(iArray).c_str()) {
326 it.second = false;
327 }
328 }
329 }
330 }
331
332 const o2::parameters::GRPMagField& getMagFieldObj() const { return mMagField; }
333 const o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() const { return mccdbMagFieldInfo; }
334 o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() { return mccdbMagFieldInfo; }
335 void updateMagFieldCCDB();
336 bool isMagFieldUpdated() const { return mMagFieldHelper.updated; }
337
338 const GRPLHCInfo& getLHCIFObj() const { return mLHCInfo; }
339 const o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() const { return mccdbLHCIFInfo; }
340 o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() { return mccdbLHCIFInfo; }
341 void updateLHCIFInfoCCDB();
342 bool isLHCIFInfoUpdated() const { return mUpdateLHCIFInfo; }
343
344 const GRPEnvVariables& getEnvVarsObj() const { return mEnvVars; }
345 GRPEnvVariables& getEnvVarsObj() { return mEnvVars; }
346 const o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() const { return mccdbEnvVarsInfo; }
347 o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() { return mccdbEnvVarsInfo; }
348 void updateEnvVarsCCDB();
349
350 const GRPCollimators& getCollimatorsObj() const { return mCollimators; }
351 GRPCollimators& getCollimatorsObj() { return mCollimators; }
352 const o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() const { return mccdbCollimatorsInfo; }
353 o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() { return mccdbCollimatorsInfo; }
355
356 void setStartValidityMagFi(long t) { mStartValidityMagFi = t; }
357 void setStartValidityLHCIF(long t) { mStartValidityLHCIF = t; }
358 void setStartValidityEnvVa(long t) { mStartValidityEnvVa = t; }
359 void setStartValidityColli(long t) { mStartValidityColli = t; }
360 long getStartValidityLHCIF() const { return mStartValidityLHCIF; }
361 long getStartValidityEnvVa() const { return mStartValidityEnvVa; }
362 long getStartValidityColli() const { return mStartValidityColli; }
366
367 void useVerboseMode() { mVerbose = true; }
368 void clearVectors() { mClearVectors = true; }
369
370 void printVectorInfo(const std::vector<std::pair<O2LongUInt, double>>& vect, bool afterUpdate);
371 void updateVector(const DPID& dpid, std::vector<std::pair<O2LongUInt, double>>& vect, std::string alias, O2LongUInt timestamp, double val);
372
373 private:
374 std::unordered_map<DPID, bool> mPids; // contains all PIDs for the processor, the bool
375 // will be true if the DP was processed at least once
376
377 long mStartValidityMagFi = o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP;
378 long mStartValidityLHCIF = o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP;
379 long mStartValidityEnvVa = o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP;
380 long mStartValidityColli = o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP;
381
382 size_t mCallSlice = 0;
383 bool mVerbose = false;
384 MagFieldHelper mMagFieldHelper;
386 o2::ccdb::CcdbObjectInfo mccdbMagFieldInfo;
387
388 GRPEnvVariables mEnvVars;
389 o2::ccdb::CcdbObjectInfo mccdbEnvVarsInfo;
390
391 GRPCollimators mCollimators;
392 o2::ccdb::CcdbObjectInfo mccdbCollimatorsInfo;
393
394 GRPLHCInfo mLHCInfo;
395 o2::ccdb::CcdbObjectInfo mccdbLHCIFInfo;
396 bool mUpdateLHCIFInfo = false;
397
398 bool mClearVectors = false;
399 std::array<std::string_view, GRPLHCInfo::nAliasesLHC> mArrLHCAliases;
400
401 ClassDefNV(GRPDCSDPsProcessor, 0);
402};
403} // namespace grp
404} // namespace o2
405
406#endif
int32_t i
Header of the General Run Parameters object for B field values.
static constexpr long INFINITE_TIMESTAMP
const o2::ccdb::CcdbObjectInfo & getccdbEnvVarsInfo() const
o2::ccdb::CcdbObjectInfo & getccdbLHCIFInfo()
o2::ccdb::CcdbObjectInfo & getccdbCollimatorsInfo()
const o2::parameters::GRPMagField & getMagFieldObj() const
o2::ccdb::CcdbObjectInfo & getccdbEnvVarsInfo()
bool processEnvVar(const DPCOM &dpcom)
void resetAndKeepLast(std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > &mapToReset)
void printVectorInfo(const std::vector< std::pair< O2LongUInt, double > > &vect, bool afterUpdate)
const o2::ccdb::CcdbObjectInfo & getccdbLHCIFInfo() const
GRPCollimators & getCollimatorsObj()
const o2::ccdb::CcdbObjectInfo & getccdbMagFieldInfo() const
bool processPairS(const DPCOM &dpcom, const std::string &alias, std::pair< O2LongUInt, std::string > &p, bool &flag)
const o2::ccdb::CcdbObjectInfo & getccdbCollimatorsInfo() const
void updateVector(const DPID &dpid, std::vector< std::pair< O2LongUInt, double > > &vect, std::string alias, O2LongUInt timestamp, double val)
bool processPairD(const DPCOM &dpcom, const std::string &alias, std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > &mapToUpdate)
const GRPLHCInfo & getLHCIFObj() const
o2::ccdb::CcdbObjectInfo & getccdbMagFieldInfo()
bool compareToLatest(std::pair< O2LongUInt, double > &p, double val)
const GRPCollimators & getCollimatorsObj() const
O2LongUInt processFlags(O2LongUInt flag, const char *pid)
int processDP(const DPCOM &dpcom)
bool processLHCIFDPs(const DPCOM &dpcom)
GRPEnvVariables & getEnvVarsObj()
void init(const std::vector< DPID > &pids)
const GRPEnvVariables & getEnvVarsObj() const
bool processCollimators(const DPCOM &dpcom)
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLuint GLfloat * val
Definition glcorearb.h:1582
O2LongUInt llu2lu(std::uint64_t v)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
unsigned long int O2LongUInt
Definition O2LongInt.h:29
std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > mCollimators
ClassDefNV(GRPCollimators, 2)
std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > mEnvVars
ClassDefNV(GRPEnvVariables, 2)
static constexpr std::string_view bptxPhaseAliases[NBPTXPhaseAliases]
std::vector< std::pair< O2LongUInt, double > > mInstLumi
std::array< std::vector< std::pair< O2LongUInt, double > >, 3 > mBackground
std::vector< std::pair< O2LongUInt, double > > mBPTXdeltaT
static constexpr std::string_view bptxPhaseShiftAliases[NBPTXPhaseShiftAliases]
static constexpr std::string_view lhcStringAliases[NLHCStringAliases]
static constexpr int nAliasesLHC
void resetAndKeepLastVector(std::vector< std::pair< O2LongUInt, double > > &vect)
static constexpr std::string_view bptxPhaseRMSAliases[NBPTXPhaseRMSAliases]
std::pair< O2LongUInt, std::string > mLumiSource
static constexpr std::string_view lumiAliases[NLumiAliases]
std::array< std::vector< std::pair< O2LongUInt, double > >, 2 > mBPTXPhaseShift
static constexpr std::string_view collimatorAliases[NCollimatorAliases]
std::array< std::vector< std::pair< O2LongUInt, double > >, 2 > mIntensityBeam
ClassDefNV(GRPLHCInfo, 1)
std::pair< O2LongUInt, std::string > mBeamMode
static constexpr std::string_view bptxAliases[NBPTXAliases]
std::array< std::vector< std::pair< O2LongUInt, double > >, 2 > mBPTXPhaseRMS
static constexpr std::string_view beamAliases[NBeamAliases]
static constexpr std::string_view bkgAliases[NBkgAliases]
std::vector< std::pair< O2LongUInt, double > > mBPTXdeltaTRMS
std::pair< O2LongUInt, std::string > mMachineMode
std::array< std::vector< std::pair< O2LongUInt, double > >, 2 > mBPTXPhase
static constexpr float ZeroCurrent
static constexpr float DeltaThreshold
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"