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);
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)
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 o2::calibration::Utils::prepareCCDBobjectInfo(obj, w, CDBTypeMap.at(calibType), md, mUpdateIntervalStart, mLastCreationTime + 2 * mCCDBupdateInterval * 1000);
174
175 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", w.getPath(), w.getFileName(), image->size(), w.getStartValidityTimestamp(), w.getEndValidityTimestamp());
176 output.snapshot(Output{CDBPayload, CDBDescMap.at(calibType), 0}, *image.get());
177 output.snapshot(Output{CDBWrapper, CDBDescMap.at(calibType), 0}, w);
178}
179
187
192{
193
194 std::vector<OutputSpec> outputs;
195 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
196 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
197
198 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
199 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
200
201 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
202 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
203
204 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalPressure)}, Lifetime::Sporadic);
205 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalPressure)}, Lifetime::Sporadic);
206
207 return DataProcessorSpec{
208 "tpc-dcs",
209 Inputs{{"input", "DCS", "TPCDATAPOINTS"}},
210 outputs,
211 AlgorithmSpec{adaptFromTask<DCSDevice>()},
212 Options{
213 {"write-debug", VariantType::Bool, false, {"write a debug output tree"}},
214 {"report-timing", VariantType::Bool, false, {"Report timing for every slice"}},
215 {"update-interval", VariantType::Int, 60 * 15, {"update interval in seconds for which ccdb entries are written"}},
216 {"fit-interval", VariantType::Int, 60 * 5, {"interval in seconds for which to e.g. perform fits of the temperature sensors"}},
217 {"round-to-interval", VariantType::Bool, false, {"round fit interval to fixed times e.g. to every 5min in the hour"}},
218 {"pressure-interval", VariantType::Int, 100, {"interval in seconds for which to average the pressure values"}},
219 {"pressure-ref-interval", VariantType::Int, 24 * 60 * 60, {"interval in seconds for which to calculate the reference pressure values"}},
220 {"update-interval-nTFs", VariantType::Int, -1, {"only used when larger than 0: update interval in nTFs for which ccdb entries are written "}}} // end Options
221 }; // end DataProcessorSpec
222}
223
224} // 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
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:103
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 sendObject(DataAllocator &output, T &obj, const CDBType calibType)
Definition DCSSpec.cxx:165
void init(o2::framework::InitContext &ic) final
Definition DCSSpec.cxx:111
void finalizeDCS(DataAllocator &output)
Definition DCSSpec.cxx:67
void updateCCDB(DataAllocator &output)
Definition DCSSpec.cxx:180
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
bool hasData() const
if data to process
void setFitInterval(dcs::TimeStampType interval)
set the fit interval
void process(const gsl::span< const DPCOM > dps)
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
GLeglImageOES image
Definition glcorearb.h:4021
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:96
DataProcessorSpec getDCSSpec()
create DCS processor
Definition DCSSpec.cxx:191
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