Project
Loading...
Searching...
No Matches
ZDCDCSDataProcessorSpec.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_ZDC_DATAPROCESSOR_H
13#define O2_ZDC_DATAPROCESSOR_H
14
17
18#include <unistd.h>
19#include <TRandom.h>
20#include <TStopwatch.h>
28#include "CCDB/CcdbApi.h"
34#include "Framework/Task.h"
35#include "Framework/Logger.h"
36
37using namespace o2::framework;
38
39namespace o2
40{
41namespace zdc
42{
43
47using namespace o2::ccdb;
50using HighResClock = std::chrono::high_resolution_clock;
51using Duration = std::chrono::duration<double, std::ratio<1, 1>>;
52
54{
55 public:
57 {
58
59 std::vector<DPID> vect;
60 mDPsUpdateInterval = ic.options().get<int64_t>("DPs-update-interval");
61 if (mDPsUpdateInterval == 0) {
62 LOG(error) << "ZDC DPs update interval was set to 0 seconds --> changed to 240";
63 mDPsUpdateInterval = 240;
64 }
65 bool useCCDBtoConfigure = ic.options().get<bool>("use-ccdb-to-configure");
66 if (useCCDBtoConfigure) {
67 LOG(info) << "Configuring via CCDB";
68 std::string ccdbpath = ic.options().get<std::string>("ccdb-path");
69 auto& mgr = CcdbManager::instance();
70 mgr.setURL(ccdbpath);
71 CcdbApi api;
72 api.init(mgr.getURL());
73 long ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
74 std::unordered_map<DPID, std::string>* dpid2Data = mgr.getForTimeStamp<std::unordered_map<DPID, std::string>>("ZDC/Calib/DCSconfig", ts);
75 for (auto& i : *dpid2Data) {
76 vect.push_back(i.first);
77 }
78 } else {
79 LOG(info) << "Configuring via hardcoded strings";
80 std::vector<std::string> aliases = {"ZDC_ZNA_POS.actual.position",
81 "ZDC_ZPA_POS.actual.position",
82 "ZDC_ZNC_POS.actual.position",
83 "ZDC_ZPC_POS.actual.position",
84 "ZDC_ZNA_HV0.actual.vMon",
85 "ZDC_ZNA_HV1.actual.vMon",
86 "ZDC_ZNA_HV2.actual.vMon",
87 "ZDC_ZNA_HV3.actual.vMon",
88 "ZDC_ZNA_HV4.actual.vMon",
89 "ZDC_ZPA_HV0.actual.vMon",
90 "ZDC_ZPA_HV1.actual.vMon",
91 "ZDC_ZPA_HV2.actual.vMon",
92 "ZDC_ZPA_HV3.actual.vMon",
93 "ZDC_ZPA_HV4.actual.vMon",
94 "ZDC_ZNC_HV0.actual.vMon",
95 "ZDC_ZNC_HV1.actual.vMon",
96 "ZDC_ZNC_HV2.actual.vMon",
97 "ZDC_ZNC_HV3.actual.vMon",
98 "ZDC_ZNC_HV4.actual.vMon",
99 "ZDC_ZPC_HV0.actual.vMon",
100 "ZDC_ZPC_HV1.actual.vMon",
101 "ZDC_ZPC_HV2.actual.vMon",
102 "ZDC_ZPC_HV3.actual.vMon",
103 "ZDC_ZPC_HV4.actual.vMon",
104 "ZDC_ZEM_HV0.actual.vMon",
105 "ZDC_ZEM_HV1.actual.vMon",
106 "ZDC_ZNA_HV0_D[1..2]",
107 "ZDC_ZNC_HV0_D[1..2]",
108 "ZDC_ZPA_HV0_D[1..2]",
109 "ZDC_ZPC_HV0_D[1..2]"};
110 std::vector<std::string> aliasesInt = {"ZDC_CONFIG_[00..32]"};
111 std::vector<std::string> expaliases = o2::dcs::expandAliases(aliases);
112 std::vector<std::string> expaliasesInt = o2::dcs::expandAliases(aliasesInt);
113 for (const auto& i : expaliases) {
114 vect.emplace_back(i, o2::dcs::RAW_DOUBLE);
115 }
116 }
117
118 LOG(info) << "Listing Data Points for ZDC:";
119 for (auto& i : vect) {
120 LOG(info) << i;
121 }
122
123 mProcessor = std::make_unique<o2::zdc::ZDCDCSProcessor>();
124 bool useVerboseMode = ic.options().get<bool>("use-verbose-mode");
125 LOG(info) << " ************************* Verbose?" << useVerboseMode;
126 if (useVerboseMode) {
127 mProcessor->useVerboseMode();
128 }
129 mProcessor->init(vect);
130 mTimer = HighResClock::now();
131 }
132
134 {
135 auto startValidity = DataRefUtils::getHeader<DataProcessingHeader*>(pc.inputs().getFirstValid(true))->creation;
136 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
137 auto timeNow = HighResClock::now();
138 if (startValidity == 0xffffffffffffffff) { // it means it is not set
139 startValidity = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
140 }
141 mProcessor->setStartValidity(startValidity);
142 mProcessor->process(dps);
143 Duration elapsedTime = timeNow - mTimer; // in seconds
144 // LOG(info) << "mDPsUpdateInterval " << mDPsUpdateInterval << "[sec.]";
145
146 if (elapsedTime.count() >= mDPsUpdateInterval) {
147 sendDPsoutput(pc.outputs());
148 mTimer = timeNow;
149 }
150 // sendLVandHVoutput(pc.outputs());
151 }
152
154 {
155 sendDPsoutput(ec.outputs());
156 // sendLVandHVoutput(ec.outputs());
157 }
158
159 private:
160 std::unique_ptr<ZDCDCSProcessor> mProcessor;
161 HighResClock::time_point mTimer;
162 int64_t mDPsUpdateInterval;
163
164 //________________________________________________________________
165 void sendDPsoutput(DataAllocator& output)
166 {
167 // extract CCDB infos and calibration object for DPs
168 mProcessor->updateDPsCCDB();
169 const auto& payload = mProcessor->getZDCDPsInfo();
170 auto& info = mProcessor->getccdbDPsInfo();
171 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
172 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
173 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
174 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "ZDC_DCSDPs", 0}, *image.get());
175 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "ZDC_DCSDPs", 0}, info);
176 mProcessor->clearDPsinfo();
177 }
178
179 //________________________________________________________________
180 void sendLVandHVoutput(DataAllocator& output)
181 {
182 // extract CCDB infos and calibration objects for LV and HV and send them to the output
183
184 if (mProcessor->isHVUpdated()) {
185 const auto& payload = mProcessor->getHVStatus();
186 auto& info = mProcessor->getccdbHVInfo();
187 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
188 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
189 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
190 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "ZDC_DCSDPs", 0}, *image.get());
191 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "ZDC_DCSDPs", 0}, info);
192 }
193 }
194
195}; // end class
196} // namespace zdc
197
198namespace framework
199{
200
201DataProcessorSpec getZDCDCSDataProcessorSpec()
202{
203
205
206 std::vector<OutputSpec> outputs;
207 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "ZDC_DCSDPs"}, Lifetime::Sporadic);
208 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "ZDC_DCSDPs"}, Lifetime::Sporadic);
209
210 return DataProcessorSpec{
211 "zdc-dcs-data-processor",
212 Inputs{{"input", "DCS", "ZDCDATAPOINTS"}},
213 outputs,
214 AlgorithmSpec{adaptFromTask<o2::zdc::ZDCDCSDataProcessor>()},
215 Options{{"ccdb-path", VariantType::String, "http://localhost:8080", {"Path to CCDB"}},
216 {"use-ccdb-to-configure", VariantType::Bool, false, {"Use CCDB to configure"}},
217 {"use-verbose-mode", VariantType::Bool, false, {"Use verbose mode"}},
218 {"DPs-update-interval", VariantType::Int64, 600ll, {"Interval (in s) after which to update the DPs CCDB entry"}}}};
219}
220
221} // namespace framework
222} // namespace o2
223
224#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 BasicCCDBManager & instance()
void init(std::string const &hosts)
Definition CcdbApi.cxx:165
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
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
struct o2::upgrades_utils::@463 zdc
structure to keep FT0 information
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"