Project
Loading...
Searching...
No Matches
StatusMapCreatorSpec.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
13
22#include "Framework/InputSpec.h"
23#include "Framework/Logger.h"
25#include "Framework/Task.h"
29#include "MCHStatus/StatusMap.h"
31#include <chrono>
32#include <fmt/format.h>
33#include <functional>
34#include <iostream>
35#include <map>
36#include <string>
37#include <vector>
38
39using namespace o2::framework;
40
41namespace o2::mch
42{
43
44size_t size(const StatusMap& sm)
45{
46 size_t n{0};
47
48 for (const auto& p : sm) {
49 ++n;
50 }
51 return n;
52}
53
55{
56 public:
57 StatusMapCreatorTask(bool useBadChannels, bool useRejectList, bool useHV,
58 std::shared_ptr<base::GRPGeomRequest> ggRequest)
59 : mUseBadChannels(useBadChannels),
60 mUseRejectList(useRejectList),
61 mUseHV(useHV),
62 mGGRequest(ggRequest) {}
63
64 void init(InitContext& ic)
65 {
66 if (mGGRequest) {
68 }
69 mBadChannels.clear();
70 mRejectList.clear();
71 mHVStatusCreator.clear();
72 mStatusMap.clear();
73 mUpdateStatusMap = false;
74
75 auto stop = [this]() {
76 auto fullTime = mFindBadHVsTime + mFindCurrentBadHVsTime + mUpdateStatusTime;
77 LOGP(info, "duration: {:g} ms (findBadHVs: {:g} ms, findCurrentBadHVs: {:g} ms, updateStatusMap: {:g} ms)",
78 fullTime.count(), mFindBadHVsTime.count(), mFindCurrentBadHVsTime.count(), mUpdateStatusTime.count());
79 };
80 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(stop);
81 }
82
83 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
84 {
85 if (matcher == ConcreteDataMatcher("MCH", "BADCHANNELS", 0)) {
86 auto bad = static_cast<std::vector<o2::mch::DsChannelId>*>(obj);
87 mBadChannels = *bad;
88 mUpdateStatusMap = true;
89 } else if (matcher == ConcreteDataMatcher("MCH", "REJECTLIST", 0)) {
90 auto rl = static_cast<std::vector<o2::mch::DsChannelId>*>(obj);
91 mRejectList = *rl;
92 mUpdateStatusMap = true;
93 } else if (matcher == ConcreteDataMatcher("MCH", "HV", 0)) {
94 auto tStart = std::chrono::high_resolution_clock::now();
95 auto hv = static_cast<o2::mch::HVStatusCreator::DPMAP*>(obj);
96 mHVStatusCreator.findBadHVs(*hv);
97 mFindBadHVsTime += std::chrono::high_resolution_clock::now() - tStart;
98 } else if (mGGRequest) {
100 }
101 }
102
104 {
105 if (mGGRequest) {
107 }
108
109 if (mUseBadChannels) {
110 // to trigger call to finaliseCCDB
111 pc.inputs().get<std::vector<o2::mch::DsChannelId>*>("badchannels");
112 }
113
114 if (mUseRejectList) {
115 // to trigger call to finaliseCCDB
116 pc.inputs().get<std::vector<o2::mch::DsChannelId>*>("rejectlist");
117 }
118
119 if (mUseHV) {
120 // to trigger call to finaliseCCDB
122
123 // check for update of bad HV channels
124 auto tStart = std::chrono::high_resolution_clock::now();
126 auto firstTForbit = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
127 auto timestamp = orbitReset + static_cast<uint64_t>(firstTForbit * constants::lhc::LHCOrbitMUS * 1.e-3);
128 if (mHVStatusCreator.findCurrentBadHVs(timestamp)) {
129 LOGP(info, "HV status updated at timestamp {}", timestamp);
130 mUpdateStatusMap = true;
131 }
132 mFindCurrentBadHVsTime += std::chrono::high_resolution_clock::now() - tStart;
133 }
134
135 // update the status map if needed
136 if (mUpdateStatusMap) {
137 updateStatusMap();
138 LOGP(info, "Sending updated StatusMap of size {}", size(mStatusMap));
139 } else {
140 LOGP(info, "Sending unchanged StatusMap of size {}", size(mStatusMap));
141 }
142
143 // create the output message
144 pc.outputs().snapshot(OutputRef{"statusmap"}, mStatusMap);
145 }
146
147 private:
148 bool mUseBadChannels{false};
149 bool mUseRejectList{false};
150 bool mUseHV{false};
151 std::shared_ptr<base::GRPGeomRequest> mGGRequest{};
152 std::vector<o2::mch::DsChannelId> mBadChannels{};
153 std::vector<o2::mch::DsChannelId> mRejectList{};
154 HVStatusCreator mHVStatusCreator{};
155 StatusMap mStatusMap{};
156 bool mUpdateStatusMap{false};
157 std::chrono::duration<double, std::milli> mFindBadHVsTime{};
158 std::chrono::duration<double, std::milli> mFindCurrentBadHVsTime{};
159 std::chrono::duration<double, std::milli> mUpdateStatusTime{};
160
161 void updateStatusMap()
162 {
163 auto tStart = std::chrono::high_resolution_clock::now();
164 mStatusMap.clear();
165 mStatusMap.add(mBadChannels, StatusMap::kBadPedestal);
166 mStatusMap.add(mRejectList, StatusMap::kRejectList);
167 mHVStatusCreator.updateStatusMap(mStatusMap);
168 mUpdateStatusMap = false;
169 mUpdateStatusTime += std::chrono::high_resolution_clock::now() - tStart;
170 }
171};
172
174{
175 auto useBadChannels = StatusMapCreatorParam::Instance().useBadChannels;
176 auto useRejectList = StatusMapCreatorParam::Instance().useRejectList;
178 std::shared_ptr<base::GRPGeomRequest> ggRequest{};
179
180 std::vector<InputSpec> inputs{};
181 if (useBadChannels) {
182 inputs.emplace_back(InputSpec{"badchannels", "MCH", "BADCHANNELS", 0, Lifetime::Condition, ccdbParamSpec("MCH/Calib/BadChannel")});
183 }
184 if (useRejectList) {
185 inputs.emplace_back(InputSpec{"rejectlist", "MCH", "REJECTLIST", 0, Lifetime::Condition, ccdbParamSpec("MCH/Calib/RejectList")});
186 }
187 if (useHV) {
188 inputs.emplace_back(InputSpec{"hv", "MCH", "HV", 0, Lifetime::Condition, ccdbParamSpec("MCH/Calib/HV", {}, 1)}); // query every TF
189
190 ggRequest = std::make_shared<base::GRPGeomRequest>(true, // orbitResetTime
191 false, // GRPECS=true
192 false, // GRPLHCIF
193 false, // GRPMagField
194 false, // askMatLUT
195 base::GRPGeomRequest::None, // geometry
196 inputs);
197 }
198
199 std::vector<OutputSpec> outputs{};
200 outputs.emplace_back(OutputSpec{{"statusmap"}, "MCH", "STATUSMAP", 0, Lifetime::Timeframe});
201
202 if (inputs.empty()) {
203 return DataProcessorSpec{
204 specName.data(),
205 {},
206 {},
208 [](ProcessingContext& ctx) {
209 ctx.services().get<ControlService>().readyToQuit(QuitRequest::Me);
210 ctx.services().get<ControlService>().endOfStream();
211 }},
212 Options{}};
213 }
214
215 return DataProcessorSpec{
216 specName.data(),
217 inputs,
218 outputs,
219 AlgorithmSpec{adaptFromTask<StatusMapCreatorTask>(useBadChannels, useRejectList, useHV, ggRequest)},
220 Options{}};
221}
222} // namespace o2::mch
Helper for geometry and GRP related CCDB requests.
Header to collect LHC related constants.
const char * specName
auto getOrbitResetTimeMS() const
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
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 findBadHVs(const DPMAP &dpMap)
std::unordered_map< DPID, std::vector< DPVAL > > DPMAP
bool findCurrentBadHVs(uint64_t timestamp)
void updateStatusMap(StatusMap &statusMap) const
void clear()
Clear the internal lists of HV issues.
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
void run(ProcessingContext &pc)
StatusMapCreatorTask(bool useBadChannels, bool useRejectList, bool useHV, std::shared_ptr< base::GRPGeomRequest > ggRequest)
void add(gsl::span< const DsChannelId > badchannels, uint32_t mask)
Definition StatusMap.cxx:36
GLdouble n
Definition glcorearb.h:1982
GLsizeiptr size
Definition glcorearb.h:659
constexpr double LHCOrbitMUS
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getStatusMapCreatorSpec(std::string_view specName="mch-statusmap-creator")
bool useBadChannels
reject bad channels (obtained during pedestal calibration runs)
bool useRejectList
use extra rejection list (relative to other bad channels sources)
bool useHV
reject channels connected to bad HV sectors