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"}},
51};
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};
109
111{
112 mWriteDebug = ic.options().get<bool>("write-debug");
113 mCCDBupdateInterval = ic.options().get<int>("update-interval");
114 mFitInterval = ic.options().get<int>("fit-interval");
115 if (mCCDBupdateInterval < 0) {
116 mCCDBupdateInterval = 0;
117 }
118 if (mFitInterval >= mCCDBupdateInterval) {
119 LOGP(info, "fit interval {} >= ccdb update interval {}, making them identical", mFitInterval, mCCDBupdateInterval);
120 mFitInterval = mCCDBupdateInterval;
121 }
122
123 mDCS.setFitInterval(mFitInterval * 1000); // in ms in mDCS
124 mDCS.setRoundToInterval(ic.options().get<bool>("round-to-interval"));
125
126 // set default meta data
127 mCDBStorage.setResponsible("Jens Wiechula (jens.wiechula@cern.ch)");
129 mCDBStorage.setReason("DCS workflow upload");
130 mReportTiming = ic.options().get<bool>("report-timing") || mWriteDebug;
131}
132
134{
135 TStopwatch sw;
136 mLastCreationTime = pc.services().get<o2::framework::TimingInfo>().creation;
137 if (mUpdateIntervalStart == 0) {
138 mUpdateIntervalStart = mLastCreationTime;
139 }
140 if (mLastCreationTime - mUpdateIntervalStart >= uint64_t(mCCDBupdateInterval * 1000)) {
141 finalizeDCS(pc.outputs());
142 mUpdateIntervalStart = mLastCreationTime;
143 }
144 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
145 mDCS.process(dps);
146 sw.Stop();
147 if (mReportTiming) {
148 LOGP(info, "Timing CPU:{:.3e} Real:{:.3e} at slice {}", sw.CpuTime(), sw.RealTime(), pc.services().get<o2::framework::TimingInfo>().timeslice);
149 }
150}
151
152template <typename T>
153void DCSDevice::sendObject(DataAllocator& output, T& obj, const CDBType calibType)
154{
155 LOGP(info, "Prepare CCDB for {}", CDBTypeMap.at(calibType));
156
157 std::map<std::string, std::string> md = mCDBStorage.getMetaData();
159 o2::calibration::Utils::prepareCCDBobjectInfo(obj, w, CDBTypeMap.at(calibType), md, mUpdateIntervalStart, mLastCreationTime - 1);
161
162 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", w.getPath(), w.getFileName(), image->size(), w.getStartValidityTimestamp(), w.getEndValidityTimestamp());
163 output.snapshot(Output{CDBPayload, CDBDescMap.at(calibType), 0}, *image.get());
164 output.snapshot(Output{CDBWrapper, CDBDescMap.at(calibType), 0}, w);
165}
166
173
178{
179
180 std::vector<OutputSpec> outputs;
181 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
182 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalTemperature)}, Lifetime::Sporadic);
183
184 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
185 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalHV)}, Lifetime::Sporadic);
186
187 outputs.emplace_back(ConcreteDataTypeMatcher{CDBPayload, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
188 outputs.emplace_back(ConcreteDataTypeMatcher{CDBWrapper, CDBDescMap.at(CDBType::CalGas)}, Lifetime::Sporadic);
189
190 return DataProcessorSpec{
191 "tpc-dcs",
192 Inputs{{"input", "DCS", "TPCDATAPOINTS"}},
193 outputs,
194 AlgorithmSpec{adaptFromTask<DCSDevice>()},
195 Options{
196 {"write-debug", VariantType::Bool, false, {"write a debug output tree"}},
197 {"report-timing", VariantType::Bool, false, {"Report timing for every slice"}},
198 {"update-interval", VariantType::Int, 60 * 5, {"update interval in seconds for which ccdb entries are written"}},
199 {"fit-interval", VariantType::Int, 60, {"interval in seconds for which to e.g. perform fits of the temperature sensors"}},
200 {"round-to-interval", VariantType::Bool, false, {"round fit interval to fixed times e.g. to every 5min in the hour"}},
201 } // end Options
202 }; // end DataProcessorSpec
203}
204
205} // 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:153
void init(o2::framework::InitContext &ic) final
Definition DCSSpec.cxx:110
void finalizeDCS(DataAllocator &output)
Definition DCSSpec.cxx:67
void updateCCDB(DataAllocator &output)
Definition DCSSpec.cxx:167
void run(o2::framework::ProcessingContext &pc) final
Definition DCSSpec.cxx:133
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 setRoundToInterval(const bool round=true)
round to fit interval
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:94
DataProcessorSpec getDCSSpec()
create DCS processor
Definition DCSSpec.cxx:177
const std::unordered_map< CDBType, o2::header::DataDescription > CDBDescMap
@ Automatic
Automatic upload.
CDBType
Calibration and parameter types for CCDB.
Definition CDBTypes.h:26
@ 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
TStopwatch sw