Project
Loading...
Searching...
No Matches
DCSSpec.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
15
16#include <chrono>
17#include <vector>
18#include <string>
19#include <string_view>
20#include <unordered_map>
21#include <TStopwatch.h>
23#include "Framework/Task.h"
24#include "Framework/Logger.h"
32
34#include "TPCdcs/DCSProcessor.h"
35#include "TPCdcs/DCSSpec.h"
36
37using namespace o2::framework;
39using HighResClock = std::chrono::high_resolution_clock;
40using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
43
44namespace o2::tpc
45{
46
47const std::unordered_map<CDBType, o2::header::DataDescription> CDBDescMap{
49 {CDBType::CalHV, o2::header::DataDescription{"TPC_HighVoltage"}},
52
54{
55 public:
56 DCSDevice() = default;
57
58 void init(o2::framework::InitContext& ic) final;
59
61
62 template <typename T>
63 void sendObject(DataAllocator& output, T& obj, const CDBType calibType, uint64_t startTime, uint64_t endTimeOverride = 0);
64
66
68 {
69 if (mDCS.hasData()) {
70 mDCS.finalizeSlot();
71 if (mWriteDebug) {
72 mDCS.writeDebug();
73 }
75 mDCS.reset();
76 }
77 }
78
79 void finalize()
80 {
81 mDCS.finalize();
82 }
83
85 {
86 LOGP(info, "endOfStream");
87 finalizeDCS(ec.outputs()); // TODO: can this also be done in stop() due to CCDB?
88 finalize();
89 }
90
91 void stop() final
92 {
93 LOGP(info, "stop");
94 finalize();
95 }
96
97 private:
98 DCSProcessor mDCS;
99 CDBStorage mCDBStorage;
100 HighResClock::time_point mIntervalStartTime;
101 uint64_t mUpdateIntervalStart{0};
102 uint64_t mLastCreationTime{0};
103 int mCCDBupdateInterval;
104 int mFitInterval;
105 bool mDebugWritten{false};
106 bool mWriteDebug{false};
107 bool mReportTiming{false};
108 int mUpdateIntervalnTFs{-1};
109};
110
112{
113 mWriteDebug = ic.options().get<bool>("write-debug");
114 mCCDBupdateInterval = ic.options().get<int>("update-interval");
115 mFitInterval = ic.options().get<int>("fit-interval");
116 const int pressureInterval = ic.options().get<int>("pressure-interval");
117 const int pressureIntervalRef = ic.options().get<int>("pressure-ref-interval");
118 if (mCCDBupdateInterval < 0) {
119 mCCDBupdateInterval = 0;
120 }
121 if (mFitInterval >= mCCDBupdateInterval) {
122 LOGP(info, "fit interval {} >= ccdb update interval {}, making them identical", mFitInterval, mCCDBupdateInterval);
123 mFitInterval = mCCDBupdateInterval;
124 }
125 mUpdateIntervalnTFs = ic.options().get<int>("update-interval-nTFs");
126
127 mDCS.setFitInterval(mFitInterval * 1000); // in ms in mDCS
128 mDCS.setPressureInterval(pressureInterval * 1000);
129 mDCS.setRefPressureInterval(pressureIntervalRef * 1000);
130 mDCS.setRoundToInterval(ic.options().get<bool>("round-to-interval"));
131
132 // set default meta data
133 mCDBStorage.setResponsible("Jens Wiechula (jens.wiechula@cern.ch)");
135 mCDBStorage.setReason("DCS workflow upload");
136 mReportTiming = ic.options().get<bool>("report-timing");
137}
138
140{
141 TStopwatch sw;
142 mLastCreationTime = pc.services().get<o2::framework::TimingInfo>().creation;
143 if (mUpdateIntervalStart == 0) {
144 mUpdateIntervalStart = mLastCreationTime;
145 }
146 if (mUpdateIntervalnTFs > 0 && (pc.services().get<o2::framework::TimingInfo>().tfCounter % mUpdateIntervalnTFs == 0)) {
147 // finalize DCS for every n-TFs (useful for testing purpose when reading in data from local file)
148 finalizeDCS(pc.outputs());
149 } else {
150 if (mLastCreationTime - mUpdateIntervalStart >= uint64_t(mCCDBupdateInterval * 1000)) {
151 finalizeDCS(pc.outputs());
152 mUpdateIntervalStart = mLastCreationTime;
153 }
154 }
155
156 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
157 mDCS.process(dps);
158 sw.Stop();
159 if (mReportTiming) {
160 LOGP(info, "Timing CPU:{:.3e} Real:{:.3e} at slice {}", sw.CpuTime(), sw.RealTime(), pc.services().get<o2::framework::TimingInfo>().timeslice);
161 }
162}
163
164template <typename T>
165void DCSDevice::sendObject(DataAllocator& output, T& obj, const CDBType calibType, uint64_t startTime, uint64_t endTimeOverride)
166{
167 LOGP(info, "Prepare CCDB for {}", CDBTypeMap.at(calibType));
168
169 std::map<std::string, std::string> md = mCDBStorage.getMetaData();
171 // for online processing extend the validity range. Will be truncated with the adjustableEOV procedure.
172 // endTimeOverride==0 (the default) means "use the generic extension"; callers that need a
173 // different end-validity (currently only pressure - see updateCCDB()) pass their own value.
174 const uint64_t endTime = endTimeOverride > 0 ? endTimeOverride : mLastCreationTime + 2 * mCCDBupdateInterval * 1000;
175 o2::calibration::Utils::prepareCCDBobjectInfo(obj, w, CDBTypeMap.at(calibType), md, startTime, endTime);
177
178 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", w.getPath(), w.getFileName(), image->size(), w.getStartValidityTimestamp(), w.getEndValidityTimestamp());
179 output.snapshot(Output{CDBPayload, CDBDescMap.at(calibType), 0}, *image.get());
180 output.snapshot(Output{CDBWrapper, CDBDescMap.at(calibType), 0}, w);
181}
182
184{
185 // only store an object if it actually received new data this slot; otherwise
186 // we'd upload an empty object, for pressure additionally tagged with a stale
187 // start-validity time left over from a previous slot
188 if (mDCS.getTimeTemperature().last > 0) {
189 sendObject(output, mDCS.getTemperature(), CDBType::CalTemperature, mUpdateIntervalStart);
190 }
191 if (mDCS.getTimeHighVoltage().last > 0) {
192 sendObject(output, mDCS.getHighVoltage(), CDBType::CalHV, mUpdateIntervalStart);
193 }
194 if (mDCS.getTimeGas().last > 0) {
195 sendObject(output, mDCS.getGas(), CDBType::CalGas, mUpdateIntervalStart);
196 }
197 if (mDCS.getTimePressure().last > 0) {
198 const auto& pressureTime = mDCS.getPressure().robustPressure.time;
199 const uint64_t genericMargin = 2 * uint64_t(mCCDBupdateInterval) * 1000;
200 const uint64_t tailMargin = 2 * uint64_t(mDCS.getPressureInterval());
201 const uint64_t pressureEnd = pressureTime.empty() ? 0 : static_cast<uint64_t>(pressureTime.back()) + std::max(genericMargin, tailMargin);
203 }
204}
205
210{
211
212 std::vector<OutputSpec> outputs;
213 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
214 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
215
216 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
217 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
218
219 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
220 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
221
222 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalPressure)}, Lifetime::Sporadic);
223 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalPressure)}, Lifetime::Sporadic);
224
225 return DataProcessorSpec{
226 "tpc-dcs",
227 Inputs{{"input", "DCS", "TPCDATAPOINTS"}},
228 outputs,
229 AlgorithmSpec{adaptFromTask<DCSDevice>()},
230 Options{
231 {"write-debug", VariantType::Bool, false, {"write a debug output tree"}},
232 {"report-timing", VariantType::Bool, false, {"Report timing for every slice"}},
233 {"update-interval", VariantType::Int, 60 * 15, {"update interval in seconds for which ccdb entries are written"}},
234 {"fit-interval", VariantType::Int, 60 * 5, {"interval in seconds for which to e.g. perform fits of the temperature sensors"}},
235 {"round-to-interval", VariantType::Bool, false, {"round fit interval to fixed times e.g. to every 5min in the hour"}},
236 {"pressure-interval", VariantType::Int, 100, {"interval in seconds for which to average the pressure values"}},
237 {"pressure-ref-interval", VariantType::Int, 24 * 60 * 60, {"interval in seconds for which to calculate the reference pressure values"}},
238 {"update-interval-nTFs", VariantType::Int, -1, {"only used when larger than 0: update interval in nTFs for which ccdb entries are written "}}} // end Options
239 }; // end DataProcessorSpec
240}
241
242} // end namespace o2::tpc
Simple interface to the CDB manager.
constexpr auto CDBWrapper
constexpr auto CDBPayload
constexpr auto CDBWrapper
Definition DCSSpec.cxx:42
constexpr auto CDBPayload
Definition DCSSpec.cxx:41
DCS processing.
Utils and constants for calibration and related workflows.
std::chrono::duration< double, std::ratio< 1, 1 > > Duration
std::chrono::high_resolution_clock HighResClock
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
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
TPC DCS data point processor.
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:109
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
void setReason(std::string_view reason)
void setIntervention(CDBIntervention const intervention)
void setResponsible(std::string_view responsible)
const auto & getMetaData() const
void init(o2::framework::InitContext &ic) final
Definition DCSSpec.cxx:111
void sendObject(DataAllocator &output, T &obj, const CDBType calibType, uint64_t startTime, uint64_t endTimeOverride=0)
Definition DCSSpec.cxx:165
void finalizeDCS(DataAllocator &output)
Definition DCSSpec.cxx:67
void updateCCDB(DataAllocator &output)
Definition DCSSpec.cxx:183
void run(o2::framework::ProcessingContext &pc) final
Definition DCSSpec.cxx:139
void stop() final
This is invoked on stop.
Definition DCSSpec.cxx:91
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
Definition DCSSpec.cxx:84
auto getPressureCCDBStartTime() const
const auto & getTimeGas() const
const auto & getTimePressure() const
bool hasData() const
if data to process
void setFitInterval(dcs::TimeStampType interval)
set the fit interval
void process(const gsl::span< const DPCOM > dps)
const auto & getTimeTemperature() const
void reset()
reset all data
void setRefPressureInterval(dcs::TimeStampType interval)
void setRoundToInterval(const bool round=true)
round to fit interval
void setPressureInterval(dcs::TimeStampType interval)
set the interval for averaging the pressure values
void writeDebug()
write the debug output tree
auto getPressureInterval() const
get fit interval
const auto & getTimeHighVoltage() const
GLeglImageOES image
Definition glcorearb.h:4021
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< InputSpec > Inputs
Global TPC definitions and constants.
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:98
DataProcessorSpec getDCSSpec()
create DCS processor
Definition DCSSpec.cxx:209
const std::unordered_map< CDBType, o2::header::DataDescription > CDBDescMap
@ Automatic
Automatic upload.
CDBType
Calibration and parameter types for CCDB.
Definition CDBTypes.h:26
@ CalPressure
DCS pressure measurements.
@ CalTemperature
DCS temperature measurements.
@ CalGas
DCS gas measurements.
@ CalHV
DCS HV measurements.
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
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
uint32_t tfCounter
the orbit the TF begins
Definition TimingInfo.h:32
TStopwatch sw