Project
Loading...
Searching...
No Matches
ZDCDCSProcessor.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
12#include "Rtypes.h"
13#include <deque>
14#include <string>
15#include <algorithm>
16#include <iterator>
17#include <string>
18#include <cstring>
19#include <bitset>
21
22using namespace o2::zdc;
23using namespace o2::dcs;
24
28
30
32{
33 LOG(info) << "First Value: timestamp = " << firstValue.first << ", value = " << firstValue.second;
34 LOG(info) << "Last Value: timestamp = " << lastValue.first << ", value = " << lastValue.second;
35 LOG(info) << "Mid Value: timestamp = " << midValue.first << ", value = " << midValue.second;
36 LOG(info) << "Max Change: timestamp = " << maxChange.first << ", value = " << maxChange.second;
37}
38
39//__________________________________________________________________
40
41void ZDCDCSProcessor::init(const std::vector<DPID>& pids)
42{
43 // fill the array of the DPIDs that will be used by ZDC
44 // pids should be provided by CCDB
45
46 for (const auto& it : pids) {
47 mPids[it] = false;
48 mZDCDCS[it].makeEmpty();
49 }
50
51 for (int iddl = 0; iddl < NDDLS; ++iddl) {
52 for (int im = 0; im < NMODULES; ++im) {
53 getZDCActiveChannels(iddl, im, mZDCMapInfo[iddl][im]);
54 }
55 }
56}
57
58//__________________________________________________________________
59
60int ZDCDCSProcessor::process(const gsl::span<const DPCOM> dps)
61{
62
63 // first we check which DPs are missing
64 if (mVerbose) {
65 LOG(info) << "\n\nProcessing new TF\n-----------------";
66 }
67 if (!mStartTFset) {
68 mStartTF = mTF;
69 mStartTFset = true;
70 }
71
72 std::unordered_map<DPID, DPVAL> mapin;
73 for (auto& it : dps) {
74 mapin[it.id] = it.data;
75 }
76 for (auto& it : mPids) {
77 const auto& el = mapin.find(it.first);
78 if (el == mapin.end()) {
79 LOG(debug) << "DP " << it.first << " not found in map";
80 } else {
81 LOG(debug) << "DP " << it.first << " found in map";
82 }
83 }
84
85 mUpdateMapping = false; // by default no new entry in the CCDB for the mapping
86 mUpdateHVStatus = false; // by default no new entry in the CCDB for the HV
87 mUpdateVerticalPosition = false; // by default no new entry in the CCDB for ZDC positions
88
89 // now we process all DPs, one by one
90 for (const auto& it : dps) {
91 // we process only the DPs defined in the configuration
92 const auto& el = mPids.find(it.id);
93 if (el == mPids.end()) {
94 LOG(info) << "DP " << it.id << " not found in ZDCDCSProcessor, will not process it";
95 continue;
96 }
97 processDP(it);
98 mPids[it.id] = true;
99 }
100
101 if (mUpdateMapping) {
103 }
104
105 if (mUpdateHVStatus) {
106 updateHVCCDB();
107 }
108
109 if (mUpdateVerticalPosition) {
111 }
112
113 return 0;
114}
115
116//__________________________________________________________________
117
119{
120
121 // processing single DP
122
123 auto& dpid = dpcom.id;
124 const auto& type = dpid.get_type();
125 auto& val = dpcom.data;
126 if (mVerbose) {
127 if (type == RAW_DOUBLE) { // positions, mapping and HV
128 LOG(info);
129 LOG(info) << "Processing DP " << dpcom << ", with value = " << o2::dcs::getValue<double>(dpcom);
130 } else if (type == RAW_INT) { // mapping
131 LOG(info);
132 LOG(info) << "Processing DP " << dpcom << ", with value = " << o2::dcs::getValue<int32_t>(dpcom);
133 }
134 }
135 auto flags = val.get_flags();
136 if (processFlags(flags, dpid.get_alias()) == 0) {
137 // access the correct element
138 if (type == RAW_DOUBLE) { // full map & positions
139 // for these DPs we store the first values
140 /*auto& dvect = mDpsdoublesmap[dpid];
141 LOG(debug) << "mDpsdoublesmap[dpid].size() = " << dvect.size();
142 auto etime = val.get_epoch_time();
143 if (dvect.size() == 0 ||
144 etime != dvect.back().get_epoch_time()) { // check timestamp (TBF)
145 dvect.push_back(val);
146 }*/
147
148 if (std::strstr(dpid.get_alias(), "position") != nullptr) { // DP from POSITION
149 std::bitset<4> posstatus(o2::dcs::getValue<double>(dpcom));
150 if (mVerbose) {
151 LOG(info) << " Prev.positions : " << mPrevPositionstatus << ", new = " << posstatus;
152 }
153 if (posstatus == mPrevPositionstatus) {
154 if (mVerbose) {
155 LOG(info) << "ZN/ZP positions unchanged, doing nothing";
156 }
157 return 0;
158 }
159 if (mVerbose) {
160 LOG(info) << "Positions modified";
161 }
162 mUpdateVerticalPosition = true;
163 mPrevPositionstatus = posstatus;
164 }
165
166 if (std::strstr(dpid.get_alias(), "HV") != nullptr) { // DP is HV value
167 std::string aliasStr(dpid.get_alias()); // of the form "ZDC_ZNA_HV0.actual.vMon"
168 const auto offs = std::strlen("ZDC_");
169 std::string detStr = aliasStr.substr(offs, 3);
170 int detID = 0; // order of the detectors: ZNA, ZPA, ZNC, ZPC, ZEM (DIFFEREMT FROM Runs1/2)
171 if ((std::strstr(detStr.c_str(), "ZNA")) != nullptr) {
172 detID = 1;
173 } else if ((std::strstr(detStr.c_str(), "ZPA")) != nullptr) {
174 detID = 2;
175 } else if ((std::strstr(detStr.c_str(), "ZNC")) != nullptr) {
176 detID = 3;
177 } else if ((std::strstr(detStr.c_str(), "ZPC")) != nullptr) {
178 detID = 4;
179 } else if ((std::strstr(detStr.c_str(), "ZEM")) != nullptr) {
180 detID = 5;
181 }
182 std::size_t pos = aliasStr.find("HV");
183 std::string chStr = aliasStr.substr(1, pos + 2); // between 0 and 4
184 auto ich = std::stoi(chStr);
185 auto hvch = 5 * (detID - 1) + ich; // ZNA[0...4],ZPA[0...4],ZNC[0...4],ZPC[0...4],ZEM[1,2]
186 std::bitset<NHVCHANNELS> hvstatus(o2::dcs::getValue<int32_t>(dpcom));
187 if (mVerbose) {
188 LOG(info) << "HV ch. " << hvch << " Prev. value = " << mPrevHVstatus << ", New value = " << hvstatus;
189 }
190 if (hvstatus == mPrevHVstatus) {
191 if (mVerbose) {
192 LOG(info) << "Same HV status as before, doing nothing";
193 }
194 return 0;
195 }
196 if (mVerbose) {
197 LOG(info) << "Something changed in HV for ch. " << hvch;
198 }
199 mUpdateHVStatus = true;
200 for (auto ich = 0; ich < NHVCHANNELS; ++ich) {
201 auto singlestripHV = hvstatus[ich];
202 if (mHV[ich] != singlestripHV) {
203 mHV[ich] = singlestripHV;
204 }
205 } // end loop on channels
206 if (mVerbose) {
207 LOG(info) << "Updating previous HV status for ch. " << hvch;
208 }
209 mPrevHVstatus = hvstatus;
210 } // end processing current DP, when it is of type HVSTATUS
211 }
212 if (type == RAW_INT) { // mapping
213 // DP processing
214 if (std::strstr(dpid.get_alias(), "CONFIG") != nullptr) { // DP from CONFIG (ie mapping)
215 std::string aliasStr(dpid.get_alias());
216 const auto offs = std::strlen("ZDC_CONFIG_");
217 std::size_t const nsta = aliasStr.find_first_of("0123456789", offs);
218 std::size_t const nend = aliasStr.find_first_not_of("0123456789", nsta);
219 std::string ddlStr = aliasStr.substr(nsta, nend != std::string::npos ? nend - nsta : nend);
220 auto iddl = std::stoi(ddlStr);
221 const auto offs1 = nend;
222 std::size_t const nsta1 = aliasStr.find_first_of("0123456789", offs1);
223 std::size_t const nend1 = aliasStr.find_first_not_of("0123456789", nsta1);
224 std::string chStr = aliasStr.substr(nsta1, nend1 != std::string::npos ? nend1 - nsta1 : nend1);
225 auto idch = std::stoi(chStr);
226 std::bitset<4> mapstatus(o2::dcs::getValue<int32_t>(dpcom));
227 if (mVerbose) {
228 LOG(info) << "DDL: " << iddl << ": Prev = " << mPreviousMapping[iddl] << ", new = " << mapstatus;
229 }
230 if (mapstatus == mPreviousMapping[iddl]) {
231 if (mVerbose) {
232 LOG(info) << "Same mapping status as before, doing nothing";
233 }
234 return 0;
235 }
236 if (mVerbose) {
237 LOG(info) << "Mapping modified for DDL" << iddl;
238 }
239 mUpdateMapping = true;
240 for (auto imod = 0; imod < NMODULES; ++imod) { // one bit per module
241 auto singlechstatus = mapstatus[imod];
242 // check on channel mapping continuity...
243 for (int ich = 0; ich < NCHANNELS; ++ich) {
244 if (idch != (4 * imod + ich)) {
245 printf("ZDC -> problem in Nchannels: expecting %d reading %d\n\n", 4 * imod + ich, idch);
246 }
247 if ((mZDCMapInfo[iddl][imod].moduleID[ich]) == -1) {
248 continue;
249 }
250 }
251 if (mVerbose) {
252 LOG(info) << "mZDCMapInfo[" << iddl << "][" << imod << "].moduleID[" << idch << "] = " << mZDCMapInfo[iddl][imod].channelValue[idch];
253 }
254 if (mMapping[idch] != singlechstatus) {
255 mMapping[idch] = singlechstatus;
256 }
257 } // end loop on modules
258 if (mVerbose) {
259 LOG(info) << "Updating previous mapping status for DDL " << iddl;
260 }
261 mPreviousMapping[iddl] = mapstatus;
262 } // end processing current DP, when it is of type MAPPING
263 }
264 }
265 return 0;
266}
267
268//______________________________________________________________________
269
270uint64_t ZDCDCSProcessor::processFlags(const uint64_t flags, const char* pid)
271{
272
273 // function to process the flag. the return code zero means that all is fine.
274 // anything else means that there was an issue
275
276 // for now, I don't know how to use the flags, so I do nothing
277 if (!mVerbose) {
278 return 0;
279 }
281 LOG(debug) << "KEEP_ALIVE_FLAG active for DP " << pid;
282 }
284 LOG(debug) << "END_FLAG active for DP " << pid;
285 }
287 LOG(debug) << "FBI_FLAG active for DP " << pid;
288 }
290 LOG(debug) << "NEW_FLAG active for DP " << pid;
291 }
293 LOG(debug) << "DIRTY_FLAG active for DP " << pid;
294 }
296 LOG(debug) << "TURN_FLAG active for DP " << pid;
297 }
299 LOG(debug) << "WRITE_FLAG active for DP " << pid;
300 }
302 LOG(debug) << "READ_FLAG active for DP " << pid;
303 }
305 LOG(debug) << "OVERWRITE_FLAG active for DP " << pid;
306 }
308 LOG(debug) << "VICTIM_FLAG active for DP " << pid;
309 }
311 LOG(debug) << "DIM_ERROR_FLAG active for DP " << pid;
312 }
314 LOG(debug) << "BAD_DPID_FLAG active for DP " << pid;
315 }
317 LOG(debug) << "BAD_FLAGS_FLAG active for DP " << pid;
318 }
320 LOG(debug) << "BAD_TIMESTAMP_FLAG active for DP " << pid;
321 }
323 LOG(debug) << "BAD_PAYLOAD_FLAG active for DP " << pid;
324 }
326 LOG(debug) << "BAD_FBI_FLAG active for DP " << pid;
327 }
328
329 return 0;
330}
331
332//______________________________________________________________________
333
335{
336 // here we create the object to then be sent to CCDB
337 LOG(info) << "Updating DCS map";
338
339 std::map<std::string, std::string> md;
340 md["responsible"] = "Chiara Oppedisano";
341 prepareCCDBobjectInfo(mZDCDCS, mccdbDPsInfo, "ZDC/Calib/DCSDPs", mTF, md); // TBF: Do we save the entire DCS map?!??
342
343 return;
344}
345
346//______________________________________________________________________
347
349{
350
351 // we need to update a CCDB for the FEAC status --> let's prepare the CCDBInfo
352
353 if (mVerbose) {
354 LOG(info) << "Mapping changed --> I will update CCDB";
355 }
356 std::map<std::string, std::string> md;
357 md["responsible"] = "Chiara Oppedisano";
358 prepareCCDBobjectInfo(mMapping, mccdbMappingInfo, "ZDC/Calib/Mapping", mTF, md);
359 return;
360}
361
362//______________________________________________________________________
363
365{
366
367 // we need to update a CCDB for the HV status --> let's prepare the CCDBInfo
368
369 if (mVerbose) {
370 LOG(info) << "At least one HV changed status --> I will update CCDB";
371 }
372 std::map<std::string, std::string> md;
373 md["responsible"] = "Chiara Oppedisano";
374 prepareCCDBobjectInfo(mHV, mccdbHVInfo, "ZDC/Calib/HVSetting", mTF, md);
375 return;
376}
377
378//______________________________________________________________________
379
381{
382
383 // we need to update a CCDB for the table position --> let's prepare the CCDBInfo
384
385 if (mVerbose) {
386 LOG(info) << "ZDC vertical positions changed --> I will update CCDB";
387 }
388 std::map<std::string, std::string> md;
389 md["responsible"] = "Chiara Oppedisano";
390 prepareCCDBobjectInfo(mVerticalPosition, mccdbPositionInfo, "ZDC/Calib/Align", mTF, md);
391 return;
392}
393
394//_______________________________________________________________________
395
396void ZDCDCSProcessor::getZDCActiveChannels(int nDDL, int nModule, ZDCModuleMap& map) const
397{
398 //
399 // based on ZDC supposed mapping: //TBF
400 //
401
402 int nActiveChannels = 0;
403 for (int ii = 0; ii < NCHANNELS; ++ii) {
404 if ((map.readChannel[ii]) == true) {
405 nActiveChannels++;
406 }
407 }
408
409 if (mVerbose) {
410 LOG(info) << "nDDL: " << nDDL << " -> Module " << nModule << " has " << nActiveChannels << " active channels";
411 }
412}
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
uint16_t pos
Definition RawData.h:3
uint16_t pid
Definition RawData.h:2
ClassImp(o2::zdc::ZDCDCSinfo)
DeliveryType get_type() const noexcept
void init(const std::vector< DPID > &pids)
static constexpr int NCHANNELS
static constexpr int NHVCHANNELS
void getZDCActiveChannels(int nDDL, int nModule, ZDCModuleMap &info) const
static constexpr int NMODULES
int processDP(const DPCOM &dpcom)
virtual uint64_t processFlags(uint64_t flag, const char *pid)
static constexpr int NDDLS
void prepareCCDBobjectInfo(T &obj, CcdbObjectInfo &info, const std::string &path, TFType tf, const std::map< std::string, std::string > &md)
int process(const gsl::span< const DPCOM > dps)
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
static constexpr uint16_t BAD_TIMESTAMP_FLAG
static constexpr uint16_t WRITE_FLAG
static constexpr uint16_t DIRTY_FLAG
static constexpr uint64_t TURN_FLAG
static constexpr uint16_t FBI_FLAG
static constexpr uint16_t END_FLAG
static constexpr uint16_t BAD_PAYLOAD_FLAG
static constexpr uint16_t BAD_DPID_FLAG
static constexpr uint16_t KEEP_ALIVE_FLAG
static constexpr uint16_t DIM_ERROR_FLAG
static constexpr uint16_t OVERWRITE_FLAG
static constexpr uint16_t BAD_FBI_FLAG
static constexpr uint16_t VICTIM_FLAG
static constexpr uint16_t BAD_FLAGS_FLAG
static constexpr uint16_t READ_FLAG
static constexpr uint16_t NEW_FLAG
std::pair< O2LongUInt, double > maxChange
std::pair< O2LongUInt, double > midValue
std::pair< O2LongUInt, double > firstValue
std::pair< O2LongUInt, double > lastValue
std::array< bool, 4 > readChannel
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"