-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDCSSpec.cxx
More file actions
197 lines (166 loc) · 6.97 KB
/
DCSSpec.cxx
File metadata and controls
197 lines (166 loc) · 6.97 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
// 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 DCSSpec.cxx
/// @author Jens Wiechula
/// @brief DCS processing
#include <chrono>
#include <vector>
#include <string>
#include <string_view>
#include <unordered_map>
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "Framework/Logger.h"
#include "Framework/ConfigParamRegistry.h"
#include "DetectorsCalibration/Utils.h"
#include "DetectorsDCS/DataPointIdentifier.h"
#include "DetectorsDCS/DataPointValue.h"
#include "DetectorsDCS/DataPointCompositeObject.h"
#include "DetectorsDCS/DeliveryType.h"
#include "DetectorsDCS/AliasExpander.h"
#include "TPCBase/CDBInterface.h"
#include "TPCdcs/DCSProcessor.h"
#include "TPCdcs/DCSSpec.h"
using namespace o2::framework;
using DPCOM = o2::dcs::DataPointCompositeObject;
using HighResClock = std::chrono::high_resolution_clock;
using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
constexpr auto CDBPayload = o2::calibration::Utils::gDataOriginCDBPayload;
constexpr auto CDBWrapper = o2::calibration::Utils::gDataOriginCDBWrapper;
namespace o2::tpc
{
const std::unordered_map<CDBType, o2::header::DataDescription> CDBDescMap{
{CDBType::CalTemperature, o2::header::DataDescription{"TPC_Temperature"}},
{CDBType::CalHV, o2::header::DataDescription{"TPC_HighVoltage"}},
{CDBType::CalGas, o2::header::DataDescription{"TPC_Gas"}},
};
class DCSDevice : public o2::framework::Task
{
public:
DCSDevice() = default;
void init(o2::framework::InitContext& ic) final;
void run(o2::framework::ProcessingContext& pc) final;
template <typename T>
void sendObject(DataAllocator& output, T& obj, const CDBType calibType, const DCSProcessor::TimeRange& timeRange);
void updateCCDB(DataAllocator& output);
void finalizeDCS(DataAllocator& output)
{
if (mDCS.hasData()) {
mDCS.finalizeSlot();
if (mWriteDebug) {
mDCS.writeDebug();
}
updateCCDB(output);
mDCS.reset();
}
}
void finalize()
{
mDCS.finalize();
}
void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
LOGP(info, "endOfStream");
finalizeDCS(ec.outputs()); // TODO: can this also be done in stop() due to CCDB?
finalize();
}
void stop() final
{
LOGP(info, "stop");
finalize();
}
private:
DCSProcessor mDCS;
CDBStorage mCDBStorage;
HighResClock::time_point mIntervalStartTime;
uint64_t mUpdateIntervalStart{0};
uint64_t mLastCreationTime{0};
int mCCDBupdateInterval;
int mFitInterval;
bool mDebugWritten{false};
bool mWriteDebug{false};
};
void DCSDevice::init(o2::framework::InitContext& ic)
{
mWriteDebug = ic.options().get<bool>("write-debug");
mCCDBupdateInterval = ic.options().get<int>("update-interval");
mFitInterval = ic.options().get<int>("fit-interval");
if (mCCDBupdateInterval < 0) {
mCCDBupdateInterval = 0;
}
if (mFitInterval >= mCCDBupdateInterval) {
LOGP(info, "fit interval {} >= ccdb update interval {}, making them identical", mFitInterval, mCCDBupdateInterval);
mFitInterval = mCCDBupdateInterval;
}
mDCS.setFitInterval(mFitInterval * 1000); // in ms in mDCS
mDCS.setRoundToInterval(ic.options().get<bool>("round-to-interval"));
// set default meta data
mCDBStorage.setResponsible("Jens Wiechula (jens.wiechula@cern.ch)");
mCDBStorage.setIntervention(CDBIntervention::Automatic);
mCDBStorage.setReason("DCS workflow upload");
}
void DCSDevice::run(o2::framework::ProcessingContext& pc)
{
mLastCreationTime = DataRefUtils::getHeader<DataProcessingHeader*>(pc.inputs().getFirstValid(true))->creation;
if (mUpdateIntervalStart == 0) {
mUpdateIntervalStart = mLastCreationTime;
}
if (mLastCreationTime - mUpdateIntervalStart >= uint64_t(mCCDBupdateInterval * 1000)) {
finalizeDCS(pc.outputs());
mUpdateIntervalStart = mLastCreationTime;
}
auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
mDCS.process(dps);
}
template <typename T>
void DCSDevice::sendObject(DataAllocator& output, T& obj, const CDBType calibType, const DCSProcessor::TimeRange& timeRange)
{
LOGP(info, "Prepare CCDB for {}", CDBTypeMap.at(calibType));
std::map<std::string, std::string> md = mCDBStorage.getMetaData();
o2::ccdb::CcdbObjectInfo w;
o2::calibration::Utils::prepareCCDBobjectInfo(obj, w, CDBTypeMap.at(calibType), md, timeRange.first, timeRange.last);
auto image = o2::ccdb::CcdbApi::createObjectImage(&obj, &w);
LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", w.getPath(), w.getFileName(), image->size(), w.getStartValidityTimestamp(), w.getEndValidityTimestamp());
output.snapshot(Output{CDBPayload, CDBDescMap.at(calibType), 0}, *image.get());
output.snapshot(Output{CDBWrapper, CDBDescMap.at(calibType), 0}, w);
}
void DCSDevice::updateCCDB(DataAllocator& output)
{
sendObject(output, mDCS.getTemperature(), CDBType::CalTemperature, mDCS.getTimeTemperature());
sendObject(output, mDCS.getHighVoltage(), CDBType::CalHV, mDCS.getTimeHighVoltage());
sendObject(output, mDCS.getGas(), CDBType::CalGas, mDCS.getTimeGas());
}
/// ===| create DCS processor |=================================================
///
///
DataProcessorSpec getDCSSpec()
{
std::vector<OutputSpec> outputs;
outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
return DataProcessorSpec{
"tpc-dcs",
Inputs{{"input", "DCS", "TPCDATAPOINTS"}},
outputs,
AlgorithmSpec{adaptFromTask<DCSDevice>()},
Options{
{"write-debug", VariantType::Bool, false, {"write a debug output tree"}},
{"update-interval", VariantType::Int, 60 * 5, {"update interval in seconds for which ccdb entries are written"}},
{"fit-interval", VariantType::Int, 60, {"interval in seconds for which to e.g. perform fits of the temperature sensors"}},
{"round-to-interval", VariantType::Bool, false, {"round fit interval to fixed times e.g. to every 5min in the hour"}},
} // end Options
}; // end DataProcessorSpec
}
} // end namespace o2::tpc