Project
Loading...
Searching...
No Matches
MFTDCSDataProcessorSpec.h
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
12#ifndef O2_MFT_DATAPROCESSOR_H
13#define O2_MFT_DATAPROCESSOR_H
14
17
18#include <unistd.h>
19#include <TRandom.h>
20#include <TStopwatch.h>
29#include "CCDB/CcdbApi.h"
35#include "Framework/Task.h"
36#include "Framework/Logger.h"
37
38using namespace o2::framework;
39
40namespace o2
41{
42namespace mft
43{
44
48using namespace o2::ccdb;
51using HighResClock = std::chrono::high_resolution_clock;
52using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
53
55{
56 public:
57 //________________________________________________________________
59 {
60 std::vector<DPID> vect;
61 mDPsUpdateInterval = ic.options().get<int64_t>("DPs-update-interval");
62 if (mDPsUpdateInterval == 0) {
63 LOG(error) << "MFT DPs update interval set to zero seconds --> changed to 60";
64 mDPsUpdateInterval = 60;
65 }
66 LOG(info) << "mDPsUpdateInterval " << mDPsUpdateInterval << "[sec.]";
67
68 bool useCCDBtoConfigure = ic.options().get<bool>("use-ccdb-to-configure");
69
70 mStart = ic.options().get<int64_t>("tstart");
71 mEnd = ic.options().get<int64_t>("tend");
72
73 mThreBBCurrent = ic.options().get<float>("thre-bb-current");
74 mThreAnalogCurrent = ic.options().get<float>("thre-analog-current");
75 mThreDigitCurrent = ic.options().get<float>("thre-digit-current");
76 mThreBBValtage = ic.options().get<float>("thre-bb-voltage");
77 mThreRULV = ic.options().get<float>("thre-ru-low-voltage");
78
79 LOG(info) << "mThreBBCurrent" << mThreBBCurrent;
80 LOG(info) << "mThreAnalogCurrent" << mThreAnalogCurrent;
81 LOG(info) << "mThreDigitCurrent" << mThreDigitCurrent;
82 LOG(info) << "mThreBBValtage" << mThreBBValtage;
83 LOG(info) << "mThreRULV" << mThreRULV;
84
85 if (useCCDBtoConfigure) {
86 LOG(info) << "Configuring via CCDB";
87
88 auto& mgr = CcdbManager::instance();
90 long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
91 std::unordered_map<DPID, std::string>* dpid2DataDesc = mgr.getForTimeStamp<std::unordered_map<DPID, std::string>>("MFT/Config/DCSDPconfig", ts);
92 for (auto& i : *dpid2DataDesc) {
93 vect.push_back(i.first);
94 }
95 }
96
97 else {
98 LOG(info) << "Configuring via hardcoded strings";
99 std::vector<std::string> aliases = {"MFT_PSU_ZONE/H[0..1]/D[0..4]/F[0..1]/Z[0..3]/Current/Analog",
100 "MFT_PSU_ZONE/H[0..1]/D[0..4]/F[0..1]/Z[0..3]/Current/BackBias",
101 "MFT_PSU_ZONE/H[0..1]/D[0..4]/F[0..1]/Z[0..3]/Current/Digital",
102 "MFT_PSU_ZONE/H[0..1]/D[0..4]/F[0..1]/Z[0..3]/Voltage/BackBias",
103 "MFT_RU_LV/H0/D0/F0/Z[0..3]/iMon",
104 "MFT_RU_LV/H0/D1/F0/Z[0..3]/iMon",
105 "MFT_RU_LV/H0/D2/F0/Z[0..3]/iMon",
106 "MFT_RU_LV/H0/D3/F0/Z[0..3]/iMon",
107 "MFT_RU_LV/H0/D4/F0/Z[0..3]/iMon",
108 "MFT_RU_LV/H0/D0/F1/Z[0..3]/iMon",
109 "MFT_RU_LV/H0/D1/F1/Z[0..3]/iMon",
110 "MFT_RU_LV/H0/D2/F1/Z[0..3]/iMon",
111 "MFT_RU_LV/H0/D3/F1/Z[0..3]/iMon",
112 "MFT_RU_LV/H0/D4/F1/Z[0..3]/iMon",
113 "MFT_RU_LV/H1/D0/F0/Z[0..3]/iMon",
114 "MFT_RU_LV/H1/D1/F0/Z[0..3]/iMon",
115 "MFT_RU_LV/H1/D2/F0/Z[0..3]/iMon",
116 "MFT_RU_LV/H1/D3/F0/Z[0..3]/iMon",
117 "MFT_RU_LV/H1/D4/F0/Z[0..3]/iMon",
118 "MFT_RU_LV/H1/D0/F1/Z[0..3]/iMon",
119 "MFT_RU_LV/H1/D1/F1/Z[0..3]/iMon",
120 "MFT_RU_LV/H1/D2/F1/Z[0..3]/iMon",
121 "MFT_RU_LV/H1/D3/F1/Z[0..3]/iMon",
122 "MFT_RU_LV/H1/D4/F1/Z[0..3]/iMon"};
123
124 std::vector<std::string> expaliases = o2::dcs::expandAliases(aliases);
125 for (const auto& i : expaliases) {
126 vect.emplace_back(i, o2::dcs::DPVAL_DOUBLE);
127 }
128 }
129
130 LOG(info) << "Listing Data Points for MFT:";
131 for (auto& i : vect) {
132 LOG(info) << i;
133 }
134
135 mProcessor = std::make_unique<o2::mft::MFTDCSProcessor>();
136 bool useVerboseMode = ic.options().get<bool>("use-verbose-mode");
137 LOG(info) << " ************************* Verbose?" << useVerboseMode;
138
139 if (useVerboseMode) {
140 mProcessor->useVerboseMode();
141 }
142 mProcessor->init(vect);
143
144 mTimer = HighResClock::now();
145 mReportTiming = ic.options().get<bool>("report-timing") || useVerboseMode;
146 }
147
148 //________________________________________________________________
150 {
151 TStopwatch sw;
152 auto tfid = o2::header::get<o2::framework::DataProcessingHeader*>(pc.inputs().get("input").header)->startTime;
153 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
154
155 mProcessor->setThreBackBiasCurrent(mThreBBCurrent);
156 mProcessor->setThreAnalogCurrent(mThreAnalogCurrent);
157 mProcessor->setThreDigitCurrent(mThreDigitCurrent);
158 mProcessor->setThreBackBiasVoltage(mThreBBValtage);
159 mProcessor->setThreRULV(mThreRULV);
160 mProcessor->setTF(tfid);
161 mProcessor->process(dps);
162
163 auto timeNow = HighResClock::now();
164 Duration elapsedTime = timeNow - mTimer; // in seconds
165 if (elapsedTime.count() >= mDPsUpdateInterval || mProcessor->sendDPsCCDB()) {
166 sendDPsoutput(pc.outputs());
167 mTimer = timeNow;
168 }
169 sw.Stop();
170 if (mReportTiming) {
171 LOGP(info, "Timing CPU:{:.3e} Real:{:.3e} at slice {}", sw.CpuTime(), sw.RealTime(), pc.services().get<o2::framework::TimingInfo>().timeslice);
172 }
173 }
174
175 //________________________________________________________________
177 {
178 sendDPsoutput(ec.outputs());
179 }
180
181 private:
182 bool mReportTiming = false;
183 std::unique_ptr<MFTDCSProcessor> mProcessor;
184 HighResClock::time_point mTimer;
185 int64_t mDPsUpdateInterval;
186 long mStart;
187 long mEnd;
188
189 float mThreBBCurrent;
190 float mThreAnalogCurrent;
191 float mThreDigitCurrent;
192 float mThreBBValtage;
193 float mThreRULV;
194
195 //________________________________________________________________
196 void sendDPsoutput(DataAllocator& output)
197 {
198 // extract CCDB infos and calibration object for DPs
199 mProcessor->updateDPsCCDB();
200 const auto& payload = mProcessor->getMFTDPsInfo();
201 auto& info = mProcessor->getccdbDPsInfo();
202
203 long tstart = mStart;
204 long tend = mEnd;
205
206 if (tstart == -1) {
208 }
209
210 if (tend == -1) {
211 tend = tstart + o2::ccdb::CcdbObjectInfo::MONTH;
212 }
213
214 info.setStartValidityTimestamp(tstart);
215 info.setEndValidityTimestamp(tend);
216
217 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
218 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
219 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
220 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "MFT_DCSDPs", 0}, *image.get());
221 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "MFT_DCSDPs", 0}, info);
222 mProcessor->clearDPsinfo();
223 }
224 //________________________________________________________________
225}; // end class
226} // namespace mft
227
228namespace framework
229{
230
231DataProcessorSpec getMFTDCSDataProcessorSpec()
232{
233
235
236 std::vector<OutputSpec> outputs;
237
238 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "MFT_DCSDPs"}, Lifetime::Sporadic);
239 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "MFT_DCSDPs"}, Lifetime::Sporadic);
240
241 return DataProcessorSpec{
242 "mft-dcs-data-processor",
243 Inputs{{"input", "DCS", "MFTDATAPOINTS"}},
244 outputs,
245 AlgorithmSpec{adaptFromTask<o2::mft::MFTDCSDataProcessor>()},
246 Options{
247 {"tstart", VariantType::Int64, -1ll, {"Start of validity timestamp"}},
248 {"tend", VariantType::Int64, -1ll, {"End of validity timestamp"}},
249 {"use-ccdb-to-configure", VariantType::Bool, false, {"Use CCDB to configure"}},
250 {"use-verbose-mode", VariantType::Bool, false, {"Use verbose mode"}},
251 {"report-timing", VariantType::Bool, false, {"Report timing for every slice"}},
252 {"thre-analog-current", VariantType::Float, 999.f, {"Threshold for Analog Currect to send to CCDB"}},
253 {"thre-digit-current", VariantType::Float, 999.f, {"Threshold for Digital Currect to send to CCDB"}},
254 {"thre-bb-current", VariantType::Float, 999.f, {"Threshold for BackBias Currect to send to CCDB"}},
255 {"thre-bb-voltage", VariantType::Float, 999.f, {"Threshold for BackBias Voltage to send to CCDB"}},
256 {"thre-ru-low-voltage", VariantType::Float, 999.f, {"Threshold for RU LV to send to CCDB"}},
257 {"DPs-update-interval", VariantType::Int64, 600ll, {"Interval (in s) after which to update the DPs CCDB entry"}}}};
258}
259
260} // namespace framework
261} // namespace o2
262
263#endif
Utils and constants for calibration and related workflows.
int32_t i
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
static std::string getCCDBServer()
Definition NameConf.cxx:110
static BasicCCDBManager & instance()
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long MONTH
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
GLeglImageOES image
Definition glcorearb.h:4021
information complementary to a CCDB object (path, metadata, startTimeValidity, endTimeValidity etc)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
std::vector< std::string > expandAliases(const std::vector< std::string > &patternedAliases)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > Inputs
std::chrono::duration< double, std::ratio< 1, 1 > > Duration
std::chrono::high_resolution_clock HighResClock
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
TStopwatch sw