Project
Loading...
Searching...
No Matches
HMPIDDCSDataProcessorSpec.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_HMPID_DATAPROCESSOR_H
13#define O2_HMPID_DATAPROCESSOR_H
14
21#include <unistd.h>
22
24
26#include "CCDB/CcdbApi.h"
32#include "Framework/Logger.h"
33#include "Framework/Task.h"
35
36namespace o2
37{
38namespace hmpid
39{
40
44using namespace o2::ccdb;
47using HighResClock = std::chrono::high_resolution_clock;
48using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
49using namespace o2::framework;
51
53{
54 public:
56 {
57
58 // will follow HMP-run by default:
59 //--local-test is passed only when using it on local installation
60 // to verify fits etc
61
62 mLocalTest = ic.options().get<bool>("local-test");
63
64 if (mLocalTest) {
65 mCheckRunStartStop = false;
66 }
67 LOGP(info, "Local test option = {} ", mLocalTest);
68 std::vector<DPID> vect;
69
70 bool useCCDBtoConfigure = ic.options().get<bool>("use-ccdb-to-configure");
71 LOGP(info, "useCCDBtoConfigure option = {} ", useCCDBtoConfigure);
72 if (useCCDBtoConfigure) {
73 LOG(info) << "Configuring via CCDB";
74 std::string ccdbpath = ic.options().get<std::string>("ccdb-path");
75 auto& mgr = CcdbManager::instance();
76 mgr.setURL(ccdbpath);
77 long ts = std::chrono::duration_cast<std::chrono::milliseconds>(
78 std::chrono::system_clock::now().time_since_epoch())
79 .count();
80 std::unordered_map<DPID, std::string>* dpid2DataDesc =
81 mgr.getForTimeStamp<std::unordered_map<DPID, std::string>>(
82 "HMP/Config/DCSDPconfig", ts);
83 for (auto& i : *dpid2DataDesc) {
84 vect.push_back(i.first);
85 }
86 } else {
87 LOG(info) << "Configuring via hardcoded strings";
88 std::vector<std::string> expaliases = o2::dcs::expandAliases(aliases);
89
90 for (const auto& i : expaliases) {
91 vect.emplace_back(i, o2::dcs::DPVAL_DOUBLE);
92 // LOG(info) << i;
93 }
94
95 } // end else
96
97 LOG(info) << "Listing Data Points for HMPID:";
98 for (auto& i : vect) {
99 LOG(info) << i;
100 }
101
102 mProcessor = std::make_unique<o2::hmpid::HMPIDDCSProcessor>();
103 bool useVerboseMode = ic.options().get<bool>("use-verbose-mode");
104 LOG(info) << " ************************* Verbose?" << useVerboseMode;
105
106 if (useVerboseMode) {
107 mProcessor->useVerboseMode();
108 }
109 mProcessor->init(vect);
110 mTimer = HighResClock::now();
111 }
112
113 //==========================================================================
114
116 {
117
118 auto timeNow = HighResClock::now();
119 long dataTime = (long)(pc.services().get<o2::framework::TimingInfo>().creation);
120 if (dataTime == 0xffffffffffffffff) {
121 dataTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
122 }
123
124 /* ef : only for local simulation to verify fits:
125 // set startValidity if not set already, and mCheckRunStartStop (--follow-hmpid-run) is not used */
126
127 if (mProcessor->getStartValidity() == o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP && mLocalTest == true) {
128 mProcessor->setStartValidity(dataTime);
129 }
130
131 if (mLocalTest == true) {
132 // ef: temporary solution since ec.services() crashes
133 testTimeStamp = (long)(pc.services().get<o2::framework::TimingInfo>().creation);
134 }
135
136 if (mCheckRunStartStop) {
137 const auto* grp = mRunChecker.check(); // check if there is a run with HMP
138 // this is an example of what it will return
139 static size_t runCount = 0;
140 const size_t logPrescale = 10;
141 if (mRunChecker.getRunStatus() == RunStatus::NONE) {
142 if ((runCount % logPrescale) == 0) {
143 LOGP(info, "No run with HMP is ongoing or finished");
144 }
145 } else if (mRunChecker.getRunStatus() ==
146 RunStatus::START) { // saw new run with wanted detectors
147 LOGP(info, "Run {} has started", mRunChecker.getFollowedRun());
148 if (grp) {
149 grp->print();
150 } else {
151 LOG(error) << "GRPECS pointer is null";
152 }
153 mProcessor->setRunNumberFromGRP(mRunChecker.getFollowedRun()); // ef: just the same as for emcal ef: set startValidity here if run-specific object
154 if (mProcessor->getStartValidity() == o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP) {
155 mProcessor->setStartValidity(dataTime);
156 }
157 } else if (mRunChecker.getRunStatus() == RunStatus::ONGOING) { // run which was already seen is still ongoing
158 if ((runCount % logPrescale) == 0) {
159 LOGP(info, "Run {} is still ongoing", mRunChecker.getFollowedRun());
160 }
161 } else if (mRunChecker.getRunStatus() == RunStatus::STOP) { // run which was already seen was stopped (EOR seen)
162 LOGP(info, "Run {} was stopped", mRunChecker.getFollowedRun());
163 }
164 runCount++;
165 } else {
166 mProcessor->setRunNumberFromGRP(-2); // ef: just the same as for emcal?
167 }
168
169 // process datapoints:
170 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
171 mProcessor->process(dps);
172
173 // ef: runspecific object : send CCDB
174 if (mCheckRunStartStop && (mRunChecker.getRunStatus() == RunStatus::STOP)) {
175 mProcessor->finalize();
176
177 mProcessor->setEndValidityRunSpecific(dataTime);
178
179 sendChargeThresOutput(pc.outputs());
180 sendRefIndexOutput(pc.outputs());
181 mProcessor->clearCCDBObjects(); // clears the vectors
182 mProcessor->resetStartValidity();
183 mProcessor->resetEndValidity();
184 }
185 }
186
187 //==========================================================================
188
190 {
191
192 // ef : only for local testing of Fits etc.:
193 if (mLocalTest) {
194 auto timeNow = HighResClock::now();
195
196 // ef: NB! crashes when using ec.services().get ...
197 long dataTime = testTimeStamp; //(long)(ec.services().get<o2::framework::TimingInfo>().creation);
198 if (dataTime == 0xffffffffffffffff) {
199 dataTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
200 }
201
202 mProcessor->setEndValidityRunIndependent(dataTime);
203 mProcessor->finalize();
204
205 sendChargeThresOutput(ec.outputs());
206 sendRefIndexOutput(ec.outputs());
207
208 mProcessor->clearCCDBObjects(); // clears the vectors
209 mProcessor->resetStartValidity();
210 mProcessor->resetEndValidity();
211 } // <end if mLocalTest>
212 }
213
214 //==========================================================================
215
216 private:
217 // fill CCDB with ChargeThresh (arQthre)
218 void sendChargeThresOutput(o2::framework::DataAllocator& output)
219 {
220 const auto& payload = mProcessor->getChargeCutObj();
221 auto& info = mProcessor->getHmpidChargeInfo();
222
223 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
224 LOG(info) << "Sending object " << info.getPath() << "/"
225 << info.getFileName() << " of size " << image->size()
226 << " bytes, valid for " << info.getStartValidityTimestamp()
227 << " : " << info.getEndValidityTimestamp();
228 output.snapshot(
230 *image.get());
231 output.snapshot(
233 info);
234 }
235
236 // fill CCDB with RefIndex (arrMean)
237 void sendRefIndexOutput(o2::framework::DataAllocator& output)
238 {
239 // fill CCDB with RefIndex (std::vector<TF1> arrMean)
240 const auto& payload = mProcessor->getRefIndexObj();
241 auto& info = mProcessor->getccdbRefInfo();
242
243 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
244 LOG(info) << "Sending object " << info.getPath() << "/"
245 << info.getFileName() << " of size " << image->size()
246 << " bytes, valid for " << info.getStartValidityTimestamp()
247 << " : " << info.getEndValidityTimestamp();
248
249 output.snapshot(
251 *image.get());
252 output.snapshot(
254 info);
255 }
256
257 std::vector<std::string> aliases = {/*"HMP_MP_[0..6]_STATUSW",*/
258 "HMP_ENV_PENV",
259 "HMP_MP_[0..6]_GAS_PMWPC",
260 "HMP_MP_[0..6]_LIQ_LOOP_RAD_[0..2]_IN_TEMP",
261 "HMP_MP_[0..6]_LIQ_LOOP_RAD_[0..2]_OUT_TEMP",
262 "HMP_MP_[0..6]_SEC_[0..5]_HV_VMON",
263 "HMP_TRANPLANT_MEASURE_[0..29]_WAVELENGHT",
264 "HMP_TRANPLANT_MEASURE_[0..29]_ARGONREFERENCE",
265 "HMP_TRANPLANT_MEASURE_[0..29]_ARGONCELL",
266 "HMP_TRANPLANT_MEASURE_[0..29]_C6F14REFERENCE",
267 "HMP_TRANPLANT_MEASURE_[0..29]_C6F14CELL"};
268
269 long testTimeStamp; // ef: ec.services Timetamp crashes
270 bool isRunStarted = false;
271 bool mLocalTest = false;
272 bool mCheckRunStartStop = true;
274
275 std::unique_ptr<HMPIDDCSProcessor> mProcessor;
276 HighResClock::time_point mTimer;
277
278}; // end class HMPIDDCSDataProcessor
279} // namespace hmpid
280
281namespace framework
282{
283
284o2::framework::DataProcessorSpec getHMPIDDCSDataProcessorSpec()
285{
286
288
289 std::vector<OutputSpec> outputs;
290 outputs.emplace_back(
292 "ChargeCut"},
293 Lifetime::Sporadic);
294 outputs.emplace_back(
296 "ChargeCut"},
297 Lifetime::Sporadic);
298
299 outputs.emplace_back(
301 "RefIndex"},
302 Lifetime::Sporadic);
303 outputs.emplace_back(
305 "RefIndex"},
306 Lifetime::Sporadic);
307
309 "hmp-dcs-data-processor", Inputs{{"input", "DCS", "HMPDATAPOINTS"}},
310 outputs, AlgorithmSpec{adaptFromTask<o2::hmpid::HMPIDDCSDataProcessor>()},
311 Options{{"ccdb-path",
314 {"Path to CCDB"}},
315 {"use-ccdb-to-configure",
317 false,
318 {"Use CCDB to configure"}},
319 {"local-test",
321 false,
322 {"Local installation test"}}, // Check HMPID runs SOR/EOR by default
323 {"use-verbose-mode",
325 false,
326 {"Use verbose mode"}}}};
327}
328
329} // namespace framework
330} // namespace o2
331
332#endif
Utils and constants for calibration and related workflows.
int32_t i
Header of the AggregatedRunInfo struct.
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 INFINITE_TIMESTAMP
RunStatus getRunStatus() const
const o2::parameters::GRPECSObject * check(long ts=-1)
static mask_t getMask(const std::string_view detList)
detector masks from any non-alpha-num delimiter-separated list (empty if NONE is supplied)
Definition DetID.cxx:42
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) 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)
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::high_resolution_clock HighResClock
std::chrono::duration< double, std::ratio< 1, 1 > > Duration
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"