|
| 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 | +/// |
| 13 | +/// \file RawDataReaderCheck.cxx |
| 14 | +/// \author Lucia Anna Tarasovicova |
| 15 | +/// |
| 16 | + |
| 17 | +#include "CTP/RawDataReaderCheck.h" |
| 18 | +#include "QualityControl/MonitorObject.h" |
| 19 | +#include "QualityControl/Quality.h" |
| 20 | +#include "QualityControl/QcInfoLogger.h" |
| 21 | +#include "DataFormatsCTP/Configuration.h" |
| 22 | +#include "DataFormatsCTP/RunManager.h" |
| 23 | +// ROOT |
| 24 | +#include <TH1.h> |
| 25 | +#include <TLatex.h> |
| 26 | +#include "DataFormatsCTP/Configuration.h" |
| 27 | +#include "CCDB/BasicCCDBManager.h" |
| 28 | +#include "DataFormatsParameters/GRPLHCIFData.h" |
| 29 | + |
| 30 | +#include <DataFormatsQualityControl/FlagReasons.h> |
| 31 | + |
| 32 | +using namespace std; |
| 33 | +using namespace o2::quality_control; |
| 34 | +using namespace o2::ctp; |
| 35 | + |
| 36 | +namespace o2::quality_control_modules::ctp |
| 37 | +{ |
| 38 | + |
| 39 | +void RawDataReaderCheck::configure() {} |
| 40 | + |
| 41 | +Quality RawDataReaderCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) |
| 42 | +{ |
| 43 | + Quality result = Quality::Null; |
| 44 | + |
| 45 | + // you can get details about the activity via the object mActivity: |
| 46 | + ILOG(Debug, Devel) << "Run " << getActivity()->mId << ", type: " << getActivity()->mType << ", beam: " << getActivity()->mBeamType << ENDM; |
| 47 | + // and you can get your custom parameters: |
| 48 | + ILOG(Debug, Devel) << "custom param physics.pp.myOwnKey1 : " << mCustomParameters.atOrDefaultValue("myOwnKey1", "physics", "pp", "default_value") << ENDM; |
| 49 | + |
| 50 | + mRunNumber = getActivity()->mId; |
| 51 | + |
| 52 | + map<string, string> metadata; // can be empty |
| 53 | + auto mo = moMap->begin()->second; |
| 54 | + mTimestamp = mo->getValidity().getMin(); |
| 55 | + auto lhcifdata = UserCodeInterface::retrieveConditionAny<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", metadata, mTimestamp); |
| 56 | + auto bfilling = lhcifdata->getBunchFilling(); |
| 57 | + std::vector<int> bcs = bfilling.getFilledBCs(); |
| 58 | + o2::ctp::BCMask* bcmask; |
| 59 | + std::bitset<o2::constants::lhc::LHCMaxBunches> lhcBC_bitset = bcmask->BCmask; |
| 60 | + lhcBC_bitset.reset(); |
| 61 | + |
| 62 | + for (auto const& bc : bcs) { |
| 63 | + lhcBC_bitset.set(bc, 1); |
| 64 | + } |
| 65 | + |
| 66 | + int threshold = 10; |
| 67 | + |
| 68 | + for (auto& [moName, mo] : *moMap) { |
| 69 | + |
| 70 | + (void)moName; |
| 71 | + if (mo->getName() == "histobc") { |
| 72 | + auto* h = dynamic_cast<TH1F*>(mo->getObject()); |
| 73 | + |
| 74 | + result = Quality::Good; |
| 75 | + result.addMetadata("BC_id", "good"); |
| 76 | + for (int i = 0; i < o2::constants::lhc::LHCMaxBunches; i++) { |
| 77 | + if (lhcBC_bitset[i] && h->GetBinContent(i + 1) < threshold) { |
| 78 | + result = Quality::Bad; |
| 79 | + result.updateMetadata(Form("BC_id%d", i + 1), "bad"); |
| 80 | + result.addReason(quality_control::FlagReasonFactory::Unknown(), "Bunch crossing is expected, but not measured"); |
| 81 | + break; |
| 82 | + } |
| 83 | + if (lhcBC_bitset[i] && h->GetBinContent(i + 1) == threshold) { |
| 84 | + result = Quality::Medium; |
| 85 | + result.updateMetadata(Form("BC_id%d", i + 1), "medium"); |
| 86 | + result.addReason(quality_control::FlagReasonFactory::Unknown(), "Bunch crossing is expected, at the threshold of background"); |
| 87 | + } |
| 88 | + if (!lhcBC_bitset[i] && h->GetBinContent(i + 1) == threshold) { |
| 89 | + result = Quality::Medium; |
| 90 | + result.updateMetadata(Form("BC_id%d", i + 1), "medium"); |
| 91 | + result.addReason(quality_control::FlagReasonFactory::Unknown(), "Bunch crossing not expected, at the threshold of background"); |
| 92 | + } |
| 93 | + if (!lhcBC_bitset[i] && h->GetBinContent(i + 1) > threshold) { |
| 94 | + result = Quality::Bad; |
| 95 | + result.updateMetadata(Form("BC_id%d", i + 1), "bad"); |
| 96 | + result.addReason(quality_control::FlagReasonFactory::Unknown(), "Bunch crossing not expected, but measured"); |
| 97 | + break; |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + return result; |
| 103 | +} |
| 104 | + |
| 105 | +std::string RawDataReaderCheck::getAcceptedType() { return "TH1"; } |
| 106 | + |
| 107 | +void RawDataReaderCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult) |
| 108 | +{ |
| 109 | + std::shared_ptr<TLatex> msg; |
| 110 | + if (mo->getName() == "histobc") { |
| 111 | + auto* h = dynamic_cast<TH1F*>(mo->getObject()); |
| 112 | + |
| 113 | + if (checkResult == Quality::Good) { |
| 114 | + h->SetLineColor(kGreen); |
| 115 | + } else if (checkResult == Quality::Bad) { |
| 116 | + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; |
| 117 | + msg = std::make_shared<TLatex>(0.15, 0.8, Form("Reason: %s", (std::get<1>(checkResult.getReasons()[0])).c_str())); |
| 118 | + msg->SetTextColor(kRed); |
| 119 | + msg->SetTextSize(0.06); |
| 120 | + msg->SetTextFont(43); |
| 121 | + msg->SetNDC(); |
| 122 | + h->GetListOfFunctions()->Add(msg->Clone()); |
| 123 | + h->SetLineColor(kRed); |
| 124 | + } else if (checkResult == Quality::Medium) { |
| 125 | + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; |
| 126 | + msg = std::make_shared<TLatex>(0.15, 0.8, Form("Reason: %s", (std::get<1>(checkResult.getReasons()[0])).c_str())); |
| 127 | + msg->SetTextColor(kOrange); |
| 128 | + msg->SetTextSize(0.06); |
| 129 | + msg->SetTextFont(43); |
| 130 | + msg->SetNDC(); |
| 131 | + h->GetListOfFunctions()->Add(msg->Clone()); |
| 132 | + h->SetLineColor(kOrange); |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +} // namespace o2::quality_control_modules::ctp |
0 commit comments