-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDCSProcessor.cxx
More file actions
238 lines (206 loc) · 7.12 KB
/
DCSProcessor.cxx
File metadata and controls
238 lines (206 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file DCSProcessor.cxx
/// @brief TPC DCS data point processor
/// @author Jens Wiechula
#include <string_view>
// ROOT includes
#include "TLinearFitter.h"
#include "TVectorD.h"
// O2 includes
#include "DetectorsDCS/DataPointIdentifier.h"
#include "DetectorsDCS/DataPointValue.h"
#include "DetectorsDCS/DeliveryType.h"
#include "Framework/Logger.h"
#include "TPCdcs/DCSProcessor.h"
using namespace o2::tpc;
using namespace o2::dcs;
void DCSProcessor::process(const gsl::span<const DPCOM> dps)
{
if (dps.size() == 0) {
return;
}
mHasData = true;
using namespace std::literals;
constexpr auto TEMP_ID{"TPC_PT"sv};
constexpr auto HV_ID{"TPC_HV"sv};
constexpr auto GAS_ID1{"TPC_GC"sv};
constexpr auto GAS_ID2{"TPC_An"sv};
for (const auto& dp : dps) {
const std::string_view alias(dp.id.get_alias());
const auto id = alias.substr(0, 6);
if (id == TEMP_ID) {
LOGP(debug, "Temperature DP: {}", alias);
fillTemperature(dp);
} else if (id == HV_ID) {
LOGP(debug, "HV DP: {}", alias);
fillHV(dp);
} else if (id == GAS_ID1 || id == GAS_ID2) {
LOGP(debug, "Gas DP: {}", alias);
fillGas(dp);
} else {
LOGP(warning, "Unknown data point: {}", alias);
}
}
}
float DCSProcessor::getValueF(const DPCOM& dp) const
{
if (dp.id.get_type() == DeliveryType::DPVAL_FLOAT) {
return o2::dcs::getValue<float>(dp);
} else if (dp.id.get_type() == DeliveryType::DPVAL_DOUBLE) {
return static_cast<float>(o2::dcs::getValue<double>(dp));
} else {
LOGP(warning, "Unexpected delivery type for {}: {}", dp.id.get_alias(), dp.id.get_type());
}
return 0.f;
}
void DCSProcessor::fillTemperature(const DPCOM& dp)
{
const std::string_view alias(dp.id.get_alias());
const auto value = getValueF(dp);
const auto time = dp.data.get_epoch_time();
mTemperature.fill(alias, time, value);
}
void DCSProcessor::fillHV(const DPCOM& dp)
{
const std::string_view alias(dp.id.get_alias());
const auto time = dp.data.get_epoch_time();
const auto type = dp.id.get_type();
if (alias.back() == 'S') { //
uint32_t value;
// TODO: Remove once type is clear
static bool statTypePrinted = false;
if (!statTypePrinted) {
LOGP(info, "Delivery type for STATUS: {}", type);
statTypePrinted = true;
}
if (type == DeliveryType::DPVAL_UINT) {
value = o2::dcs::getValue<uint32_t>(dp);
} else if (type == DeliveryType::DPVAL_INT) {
value = uint32_t(o2::dcs::getValue<int32_t>(dp));
} else {
value = uint32_t(getValueF(dp));
}
mHighVoltage.fillStatus(alias, time, value);
} else {
// TODO: Remove once type is clear
static bool uiTypePrinted = false;
if (!uiTypePrinted) {
LOGP(info, "Delivery type for current, voltage: {}", type);
uiTypePrinted = true;
}
const auto value = getValueF(dp);
mHighVoltage.fillUI(alias, time, value);
}
}
void DCSProcessor::fillGas(const DPCOM& dp)
{
const std::string_view alias(dp.id.get_alias());
const auto value = getValueF(dp);
const auto time = dp.data.get_epoch_time();
mGas.fill(alias, time, value);
}
void DCSProcessor::finalizeSlot()
{
finalizeTemperature();
finalizeHighVoltage();
finalizeGas();
mHasData = false;
}
void DCSProcessor::fitTemperature(Side side)
{
//// temperature fits in x-y
TLinearFitter fitter(3, "x0 ++ x1 ++ x2");
bool nextInterval = true;
std::array<size_t, dcs::Temperature::SensorsPerSide> startPos{};
const size_t sensorOffset = (side == Side::C) ? dcs::Temperature::SensorsPerSide : 0;
dcs::TimeStampType refTime = getMinTime(mTemperature.raw);
while (nextInterval) {
// TODO: check if we should use refTime
dcs::TimeStampType firstTime = std::numeric_limits<dcs::TimeStampType>::max();
nextInterval = false;
for (size_t iSensor = 0; iSensor < dcs::Temperature::SensorsPerSide; ++iSensor) {
const auto& sensor = mTemperature.raw[iSensor + sensorOffset];
LOGP(debug, "sensor {}, start {}, size {}", sensor.sensorNumber, startPos[iSensor], sensor.data.size());
while (startPos[iSensor] < sensor.data.size()) {
nextInterval = true;
const auto& dataPoint = sensor.data[startPos[iSensor]];
if ((dataPoint.time - refTime) >= mFitInterval) {
LOGP(debug, "sensor {}, {} - {} >= {}", sensor.sensorNumber, dataPoint.time, refTime, mFitInterval);
break;
}
firstTime = std::min(firstTime, dataPoint.time);
const auto temperature = dataPoint.value;
// sanity check
if (temperature < 15 || temperature > 25) {
++startPos[iSensor];
continue;
}
const auto& pos = dcs::Temperature::SensorPosition[iSensor + sensorOffset];
double x[] = {1., double(pos.x), double(pos.y)};
fitter.AddPoint(x, temperature, 1);
++startPos[iSensor];
}
}
if (firstTime < std::numeric_limits<dcs::TimeStampType>::max()) {
fitter.Eval();
LOGP(info, "Side {}, fit interval {} - {} with {} points", int(side), refTime, refTime + mFitInterval - 1, fitter.GetNpoints());
auto& stats = (side == Side::A) ? mTemperature.statsA : mTemperature.statsC;
auto& stat = stats.data.emplace_back();
stat.time = firstTime;
stat.value.mean = fitter.GetParameter(0);
stat.value.gradX = fitter.GetParameter(1);
stat.value.gradY = fitter.GetParameter(2);
fitter.ClearPoints();
refTime += mFitInterval;
}
}
}
void DCSProcessor::finalizeTemperature()
{
mTemperature.sortAndClean();
fitTemperature(Side::A);
fitTemperature(Side::C);
mTimeTemperature = {getMinTime(mTemperature.raw), getMaxTime(mTemperature.raw)};
}
void DCSProcessor::finalizeHighVoltage()
{
mHighVoltage.sortAndClean();
auto minTime = getMinTime(mHighVoltage.currents);
minTime = std::min(minTime, getMinTime(mHighVoltage.voltages));
minTime = std::min(minTime, getMinTime(mHighVoltage.states));
auto maxTime = getMaxTime(mHighVoltage.currents);
maxTime = std::max(maxTime, getMaxTime(mHighVoltage.voltages));
maxTime = std::max(maxTime, getMaxTime(mHighVoltage.states));
mTimeHighVoltage = {minTime, maxTime};
}
void DCSProcessor::finalizeGas()
{
mGas.sortAndClean();
mTimeGas = {mGas.getMinTime(), mGas.getMaxTime()};
}
void DCSProcessor::writeDebug()
{
if (!mDebugStream) {
mDebugStream = std::make_unique<o2::utils::TreeStreamRedirector>(mDebugOutputName.data(), "recreate");
}
*mDebugStream << "dcs"
<< "Temperature=" << mTemperature
<< "HV=" << mHighVoltage
<< "Gas=" << mGas
<< "\n";
}
void DCSProcessor::finalize()
{
if (mDebugStream) {
mDebugStream->Close();
}
}