Project
Loading...
Searching...
No Matches
GRPDCSDPsProcessor.cxx
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
14#include "Rtypes.h"
15#include <cmath>
16
17using namespace o2::grp;
18using namespace o2::dcs;
19
23
24//__________________________________________________________________
25
26void GRPDCSDPsProcessor::init(const std::vector<DPID>& pids)
27{
28 // fill the array of the DPIDs that will be used by GRP
29 // pids should be provided by CCDB
30
31 for (const auto& it : pids) {
32 mPids[it] = false;
33 }
34 mMagFieldHelper.verbose = mVerbose;
35
36 // initializing vector of aliases for LHC IF DPs
37 int lastFilledElement = 0;
39 mArrLHCAliases[i] = GRPLHCInfo::collimatorAliases[i];
40 }
42
43 for (int i = 0; i < GRPLHCInfo::BeamAliases::NBeamAliases; ++i) {
44 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::beamAliases[i];
45 }
46 lastFilledElement += GRPLHCInfo::BeamAliases::NBeamAliases;
47
48 for (int i = 0; i < GRPLHCInfo::BkgAliases::NBkgAliases; ++i) {
49 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::bkgAliases[i];
50 }
51 lastFilledElement += GRPLHCInfo::BkgAliases::NBkgAliases;
52
53 for (int i = 0; i < GRPLHCInfo::BPTXAliases::NBPTXAliases; ++i) {
54 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::bptxAliases[i];
55 }
56 lastFilledElement += GRPLHCInfo::BPTXAliases::NBPTXAliases;
57
59 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::bptxPhaseAliases[i];
60 }
62
64 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::bptxPhaseRMSAliases[i];
65 }
67
69 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::bptxPhaseShiftAliases[i];
70 }
72
73 for (int i = 0; i < GRPLHCInfo::LumiAliases::NLumiAliases; ++i) {
74 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::lumiAliases[i];
75 }
76 lastFilledElement += GRPLHCInfo::LumiAliases::NLumiAliases;
77
79 mArrLHCAliases[i + lastFilledElement] = GRPLHCInfo::lhcStringAliases[i];
80 }
82
83 if (lastFilledElement != GRPLHCInfo::nAliasesLHC) {
84 LOG(fatal) << "Something went wrong definining aliases, expected " << GRPLHCInfo::nAliasesLHC << ", found " << lastFilledElement;
85 }
86}
87//__________________________________________________________________
88
89int GRPDCSDPsProcessor::process(const gsl::span<const DPCOM> dps)
90{
91
92 // first we check which DPs are missing - if some are, it means that
93 // the delta map was sent
94 if (mVerbose) {
95 LOG(info) << "\n\n\nProcessing new TF\n-----------------";
96 }
97 mMagFieldHelper.updated = false;
98
99 mUpdateLHCIFInfo = false; // by default, we do not foresee a new entry in the CCDB for the LHCIF DPs
100
101 // now we process all DPs, one by one
102 for (const auto& it : dps) {
103 processDP(it);
104 mPids[it.id] = true;
105 }
106
107 if (isMagFieldUpdated()) {
109 }
110 mCallSlice++;
111 return 0;
112}
113
114//__________________________________________________________________
116{
117
118 // processing single DP
119
120 auto& dpid = dpcom.id;
121 const auto& type = dpid.get_type();
122 auto& val = dpcom.data;
123 if (mVerbose) {
124 if (type == DPVAL_DOUBLE) {
125 LOG(info);
126 LOG(info) << "Processing DP = " << dpcom << ", with double value = " << o2::dcs::getValue<double>(dpcom);
127 } else if (type == DPVAL_BOOL) {
128 LOG(info);
129 LOG(info) << "Processing DP = " << dpcom << ", with bool value = " << o2::dcs::getValue<bool>(dpcom);
130 } else if (type == DPVAL_STRING) {
131 LOG(info);
132 LOG(info) << "Processing DP = " << dpcom << ", with string value = " << o2::dcs::getValue<std::string>(dpcom);
133 }
134 }
135 auto flags = val.get_flags();
136 if (processFlags(flags, dpid.get_alias()) == 0) {
137 // now I need to access the correct element
138 std::string aliasStr(dpid.get_alias());
139 // LOG(info) << "alias 0 = " << aliasStr;
140 // B-field DPs
141 if (aliasStr == "L3Current") {
142 mMagFieldHelper.updateCurL3(static_cast<float>(o2::dcs::getValue<double>(dpcom)));
143 } else if (aliasStr == "DipoleCurrent") {
144 mMagFieldHelper.updateCurDip(static_cast<float>(o2::dcs::getValue<double>(dpcom)));
145 } else if (aliasStr == "L3Polarity") {
146 mMagFieldHelper.updateSignL3(o2::dcs::getValue<bool>(dpcom)); // true is negative
147 } else if (aliasStr == "DipolePolarity") {
148 mMagFieldHelper.updateSignDip(o2::dcs::getValue<bool>(dpcom)); // true is negative
149 } else if (processEnvVar(dpcom)) { // environment variables
150 } else if (processCollimators(dpcom)) {
151 } else {
152 processLHCIFDPs(dpcom);
153 }
154 }
155 return 0;
156}
157
158//______________________________________________________________________
159
173
174//______________________________________________________________________
175
177{
178 // function to process Data Points that are related to env variables
179 bool match = processPairD(dpcom, "CavernTemperature", mEnvVars.mEnvVars) ||
180 processPairD(dpcom, "CavernAtmosPressure", mEnvVars.mEnvVars) ||
181 processPairD(dpcom, "SurfaceAtmosPressure", mEnvVars.mEnvVars) ||
182 processPairD(dpcom, "CavernAtmosPressure2", mEnvVars.mEnvVars);
183
184 return match;
185}
186
187//______________________________________________________________________
188bool GRPDCSDPsProcessor::processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map<std::string, std::vector<std::pair<O2LongUInt, double>>>& mapToUpdate)
189{
190
191 // function to process Data Points that is stored in a pair
192
193 auto& vect = mapToUpdate[alias]; // we also create at this point the vector in the map if it did not exist yet
194
195 auto& dpcomdata = dpcom.data;
196 auto& dpid = dpcom.id;
197 std::string aliasStr(dpid.get_alias());
198
199 if (aliasStr == alias) {
200 if (mVerbose) {
201 LOG(info) << "It matches the requested string " << alias << ", let's check if the value needs to be updated";
202 }
203 updateVector(dpid, mapToUpdate[alias], aliasStr, dpcomdata.get_epoch_time(), o2::dcs::getValue<double>(dpcom));
204 return true;
205 }
206 return false;
207}
208
209//______________________________________________________________________
210bool GRPDCSDPsProcessor::processPairS(const DPCOM& dpcom, const std::string& alias, std::pair<O2LongUInt, std::string>& p, bool& flag)
211{
212
213 // function to process string Data Points that is stored in a pair
214
215 auto& dpcomdata = dpcom.data;
216 auto& dpid = dpcom.id;
217 std::string aliasStr(dpid.get_alias());
218
219 if (aliasStr == alias) {
220 auto val = o2::dcs::getValue<std::string>(dpcom);
221 if (mVerbose) {
222 LOG(info) << "It matches the requested string " << alias << ", let's check if the value needs to be updated";
223 LOG(info) << "old value = " << p.second << ", new value = " << val << ", call " << mCallSlice;
224 }
225 if (mCallSlice == 0 || (val != p.second)) {
226 p.first = dpcomdata.get_epoch_time();
227 p.second = val;
228 flag = true;
229 if (mVerbose) {
230 LOG(info) << "Updating value " << alias << " with timestamp " << p.first;
231 }
232 }
233 return true;
234 }
235 return false;
236}
237
238//______________________________________________________________________
239
240bool GRPDCSDPsProcessor::compareToLatest(std::pair<O2LongUInt, double>& p, double val)
241{
242
243 // check if the content of the pair should be updated
244
245 if (mVerbose) {
246 LOG(info) << "old value = " << p.second << ", new value = " << val << ", absolute difference = " << std::abs(p.second - val) << " call " << mCallSlice;
247 }
248 if (mCallSlice == 0 || (std::abs(p.second - val) > 0.5e-7 * (std::abs(p.second) + std::abs(val)))) {
249 if (mVerbose) {
250 LOG(info) << "value will be updated";
251 }
252 return true;
253 }
254 if (mVerbose) {
255 LOG(info) << "value will not be updated";
256 }
257 return false;
258}
259
260//______________________________________________________________________
261
263{
264
265 // function to process the remaining LHCIF DPs
266
267 auto& dpcomdata = dpcom.data;
268 auto& dpid = dpcom.id;
269 std::string aliasStr(dpid.get_alias());
270 if (mVerbose) {
271 LOG(info) << "Processing LHCIF DP " << aliasStr;
272 }
273 const auto& type = dpid.get_type();
274 double val = -99999999;
275 if (type == DPVAL_DOUBLE || type == RAW_DOUBLE) {
276 val = o2::dcs::getValue<double>(dpcom);
277 }
278
279 for (int ibeam = 0; ibeam < GRPLHCInfo::BeamAliases::NBeamAliases; ++ibeam) {
280 if (aliasStr.find(static_cast<std::string>(GRPLHCInfo::beamAliases[ibeam])) != string::npos) {
281 updateVector(dpid, mLHCInfo.mIntensityBeam[ibeam], aliasStr, dpcomdata.get_epoch_time(), val);
282 return true;
283 }
284 }
285
286 if (aliasStr.find("BPTX") != string::npos) {
287 if (aliasStr == static_cast<std::string>(GRPLHCInfo::bptxAliases[GRPLHCInfo::BPTXAliases::BPTX_deltaT_B1_B2])) {
288 updateVector(dpid, mLHCInfo.mBPTXdeltaT, aliasStr, dpcomdata.get_epoch_time(), val);
289 return true;
290 }
291 if (aliasStr == static_cast<std::string>(GRPLHCInfo::bptxAliases[GRPLHCInfo::BPTXAliases::BPTX_deltaTRMS_B1_B2])) {
292 updateVector(dpid, mLHCInfo.mBPTXdeltaTRMS, aliasStr, dpcomdata.get_epoch_time(), val);
293 return true;
294 }
295 for (int ibeam = 0; ibeam < GRPLHCInfo::BPTXPhaseAliases::NBPTXPhaseAliases; ++ibeam) {
296 if (aliasStr == static_cast<std::string>(GRPLHCInfo::bptxPhaseAliases[ibeam])) {
297 updateVector(dpid, mLHCInfo.mBPTXPhase[ibeam], aliasStr, dpcomdata.get_epoch_time(), val);
298 return true;
299 }
300 }
301 for (int ibeam = 0; ibeam < GRPLHCInfo::BPTXPhaseRMSAliases::NBPTXPhaseRMSAliases; ++ibeam) {
302 if (aliasStr == static_cast<std::string>(GRPLHCInfo::bptxPhaseRMSAliases[ibeam])) {
303 updateVector(dpid, mLHCInfo.mBPTXPhaseRMS[ibeam], aliasStr, dpcomdata.get_epoch_time(), val);
304 return true;
305 }
306 }
307 for (int ibeam = 0; ibeam < GRPLHCInfo::BPTXPhaseShiftAliases::NBPTXPhaseShiftAliases; ++ibeam) {
308 if (aliasStr == static_cast<std::string>(GRPLHCInfo::bptxPhaseShiftAliases[ibeam])) {
309 updateVector(dpid, mLHCInfo.mBPTXPhaseShift[ibeam], aliasStr, dpcomdata.get_epoch_time(), val);
310 return true;
311 }
312 }
313 }
314
315 if (aliasStr == static_cast<std::string>(GRPLHCInfo::lumiAliases[GRPLHCInfo::LumiAliases::ALI_Lumi_Total_Inst])) {
316 updateVector(dpid, mLHCInfo.mInstLumi, aliasStr, dpcomdata.get_epoch_time(), val);
317 return true;
318 }
319
320 for (int ibkg = 0; ibkg < 3; ++ibkg) {
321 if (aliasStr.find(static_cast<std::string>(GRPLHCInfo::bkgAliases[ibkg])) != string::npos) {
322 updateVector(dpid, mLHCInfo.mBackground[ibkg], aliasStr, dpcomdata.get_epoch_time(), val);
323 return true;
324 }
325 }
326
327 if (processPairS(dpcom, static_cast<std::string>(GRPLHCInfo::lhcStringAliases[GRPLHCInfo::LHCStringAliases::ALI_Lumi_Source_Name]), mLHCInfo.mLumiSource, mUpdateLHCIFInfo)) {
328 return true;
329 }
330 if (processPairS(dpcom, static_cast<std::string>(GRPLHCInfo::lhcStringAliases[GRPLHCInfo::LHCStringAliases::MACHINE_MODE]), mLHCInfo.mMachineMode, mUpdateLHCIFInfo)) {
331 return true;
332 }
333 if (processPairS(dpcom, static_cast<std::string>(GRPLHCInfo::lhcStringAliases[GRPLHCInfo::LHCStringAliases::BEAM_MODE]), mLHCInfo.mBeamMode, mUpdateLHCIFInfo)) {
334 return true;
335 }
336
337 // LOG(error) << "DP " << aliasStr << " not known for GRP, please check";
338 return false;
339}
340
341//______________________________________________________________________
342
344{
345 // we need to update a CCDB for the B field --> let's prepare the CCDBInfo
346 if (mVerbose) {
347 LOG(info) << "At least one DP related to B field changed --> we will update CCDB with startTime " << mStartValidityMagFi;
348 }
349 if (mMagFieldHelper.isSet != (0x1 << 4) - 1) {
350 LOG(alarm) << "Magnetic field was updated but not all fields were set: no FBI was seen?";
351 mMagFieldHelper.updated = false;
352 return;
353 }
354 mMagField.setL3Current(mMagFieldHelper.negL3 ? -mMagFieldHelper.curL3 : mMagFieldHelper.curL3);
355 mMagField.setDipoleCurrent(mMagFieldHelper.negDip ? -mMagFieldHelper.curDip : mMagFieldHelper.curDip);
356 std::map<std::string, std::string> md;
357 md["responsible"] = "Chiara Zampolli";
358 o2::calibration::Utils::prepareCCDBobjectInfo(mMagField, mccdbMagFieldInfo, "GLO/Config/GRPMagField", md, mStartValidityMagFi, mStartValidityMagFi + o2::ccdb::CcdbObjectInfo::MONTH);
359}
360
361//______________________________________________________________________
362
364{
365
366 // we need to update a CCDB for the LHCIF DPs --> let's prepare the CCDBInfo
367
368 if (mVerbose) {
369 LOG(info) << "Entry related to LHCIF needs to be updated with startTime " << mStartValidityLHCIF;
370 }
371 std::map<std::string, std::string> md;
372 md["responsible"] = "Chiara Zampolli";
373 o2::calibration::Utils::prepareCCDBobjectInfo(mLHCInfo, mccdbLHCIFInfo, "GLO/Config/LHCIFDataPoints", md, mStartValidityLHCIF, mStartValidityLHCIF + 3 * o2::ccdb::CcdbObjectInfo::DAY); // valid for 3 days
374 return;
375}
376
377//______________________________________________________________________
378
380{
381
382 // we need to update a CCDB for the Env Variables DPs --> let's prepare the CCDBInfo
383
384 if (mVerbose) {
385 LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mStartValidityEnvVa;
386 }
387 std::map<std::string, std::string> md;
388 md["responsible"] = "Chiara Zampolli";
389 o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbEnvVarsInfo, "GLO/Config/EnvVars", md, mStartValidityEnvVa, mStartValidityEnvVa + 3 * o2::ccdb::CcdbObjectInfo::DAY); // valid for 3 days
390 return;
391}
392
393//______________________________________________________________________
394
396{
397
398 // we need to update a CCDB for the Collimators Variables DPs --> let's prepare the CCDBInfo
399
400 if (mVerbose) {
401 LOG(info) << "Entry related to Collimators needs to be updated with startTime " << mStartValidityColli;
402 }
403 std::map<std::string, std::string> md;
404 md["responsible"] = "Chiara Zampolli";
405 o2::calibration::Utils::prepareCCDBobjectInfo(mCollimators, mccdbCollimatorsInfo, "GLO/Config/Collimators", md, mStartValidityColli, mStartValidityColli + 3 * o2::ccdb::CcdbObjectInfo::DAY); // valid for 3 days
406 return;
407}
408
409//______________________________________________________________________
410
411void GRPDCSDPsProcessor::printVectorInfo(const std::vector<std::pair<O2LongUInt, double>>& vect, bool afterUpdate)
412{
413
414 std::string stage = afterUpdate ? "after update" : "before update";
415 if (mVerbose) {
416 LOG(info) << "size " << stage << " : " << vect.size();
417 for (const auto& it : vect) {
418 LOG(info) << it.first << ", " << it.second;
419 }
420 }
421}
422
423//______________________________________________________________________
424
425void GRPDCSDPsProcessor::updateVector(const DPID& dpid, std::vector<std::pair<O2LongUInt, double>>& vect, std::string alias, O2LongUInt timestamp, double val)
426{
427 printVectorInfo(vect, 0);
428 bool updateFlag = false;
429
430 if (!mClearVectors) {
431 if (mPids[dpid] == false) { // let's remove the first value when it is the leftover from the previous processing, since we now have a newer one
432 if (mVerbose) {
433 LOG(info) << "We will clear the existing vector, since it is the very first time we receive values for it and we have a dummy one, or the only value present is from the previous processing, so it is old";
434 }
435 vect.clear(); // won't hurt if the vector is empty as at the very beginning of the processing
436 updateFlag = true;
437 }
438 } else { // we are accumulating entries in the vector already
439 if (mVerbose) {
440 LOG(info) << "We will just update the existing vector without clearing it";
441 }
442 updateFlag = compareToLatest(vect.back(), val);
443 }
444
445 // add new value if needed
446 if (updateFlag) {
447 vect.emplace_back(timestamp, val);
448 if (mVerbose) {
449 LOG(info) << "Adding value " << val << " with timestamp " << timestamp << " to vector for DP " << alias;
450 }
451 }
452 printVectorInfo(vect, 1);
453}
Utils and constants for calibration and related workflows.
int32_t i
static constexpr long MONTH
static constexpr long DAY
DeliveryType get_type() const noexcept
bool processEnvVar(const DPCOM &dpcom)
void printVectorInfo(const std::vector< std::pair< O2LongUInt, double > > &vect, bool afterUpdate)
int process(const gsl::span< const DPCOM > dps)
bool processPairS(const DPCOM &dpcom, const std::string &alias, std::pair< O2LongUInt, std::string > &p, bool &flag)
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)
bool compareToLatest(std::pair< O2LongUInt, double > &p, double val)
O2LongUInt processFlags(O2LongUInt flag, const char *pid)
int processDP(const DPCOM &dpcom)
bool processLHCIFDPs(const DPCOM &dpcom)
void init(const std::vector< DPID > &pids)
bool processCollimators(const DPCOM &dpcom)
void setDipoleCurrent(o2::units::Current_t v)
Definition GRPMagField.h:52
void setL3Current(o2::units::Current_t v)
Definition GRPMagField.h:51
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
GLbitfield flags
Definition glcorearb.h:1570
std::string timestamp() noexcept
Definition Clock.h:84
unsigned long int O2LongUInt
Definition O2LongInt.h:29
static void prepareCCDBobjectInfo(T &obj, o2::ccdb::CcdbObjectInfo &info, const std::string &path, const std::map< std::string, std::string > &md, long start, long end=-1)
Definition Utils.h:91
std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > mCollimators
std::unordered_map< std::string, std::vector< std::pair< O2LongUInt, double > > > mEnvVars
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
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
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
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"