Project
Loading...
Searching...
No Matches
RawCheckerSpec.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
16
18
19#include <fstream>
20#include <chrono>
23#include "Framework/Logger.h"
25#include "Framework/Task.h"
27#include "MIDRaw/CrateMasks.h"
29
30namespace o2
31{
32namespace mid
33{
34
35template <typename RAWCHECKER>
36std::string getSummary(const RAWCHECKER& checker, size_t maxErrors)
37{
38 std::stringstream ss;
39 if (checker.getNEventsFaulty() >= maxErrors) {
40 ss << "Too many errors found (" << checker.getNEventsFaulty() << "): abort check!\n";
41 }
42 ss << "Number of busy raised: " << checker.getNBusyRaised() << "\n";
43 ss << "Fraction of faulty events: " << checker.getNEventsFaulty() << " / " << checker.getNEventsProcessed() << " = " << static_cast<double>(checker.getNEventsFaulty()) / ((checker.getNEventsProcessed() > 0) ? static_cast<double>(checker.getNEventsProcessed()) : 1.);
44 return ss.str();
45}
46
47template <typename RAWCHECKER>
49{
50 public:
51 RawCheckerDeviceDPL(const std::vector<uint16_t>& feeIds, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay) : mFeeIds(feeIds), mCrateMasks(crateMasks), mElectronicsDelay(electronicsDelay) {}
52
54 {
55
56 auto syncTrigger = ic.options().get<int>("mid-checker-sync-trigger");
57 mChecker.setSyncTrigger(syncTrigger);
58
59 auto outFilename = ic.options().get<std::string>("mid-checker-outfile");
60 mChecker.setElectronicsDelay(mElectronicsDelay);
61 if constexpr (std::is_same_v<RAWCHECKER, RawDataChecker>) {
62 mChecker.init(mCrateMasks);
63 if (outFilename.empty()) {
64 outFilename = "raw_checker_out.txt";
65 }
66 } else {
67 auto idx = ic.services().get<o2::framework::ParallelContext>().index1D();
68 auto feeId = mFeeIds[idx];
69 mChecker.init(feeId, mCrateMasks.getMask(feeId));
70 if (outFilename.empty()) {
71 std::stringstream ss;
72 ss << "raw_checker_out_GBT_" << feeId << ".txt";
73 outFilename = ss.str();
74 }
75 }
76
77 mOutFile.open(outFilename.c_str());
78
79 auto stop = [this]() {
80 if constexpr (std::is_same_v<RAWCHECKER, RawDataChecker>) {
81 if (!mChecker.checkMissingLinks()) {
82 mOutFile << mChecker.getDebugMessage() << "\n";
83 }
84 }
85 bool hasProcessed = (mChecker.getNEventsProcessed() > 0);
86 double scaleFactor = (mChecker.getNEventsProcessed() > 0) ? 1.e6 / static_cast<double>(mChecker.getNEventsProcessed()) : 0.;
87 LOG(info) << "Processing time / " << mChecker.getNEventsProcessed() << " BCs: full: " << mTimer.count() * scaleFactor << " us checker: " << mTimerAlgo.count() * scaleFactor << " us";
88 std::string summary = getSummary(mChecker, mMaxErrors);
89 mOutFile << summary << "\n";
90 LOG(info) << summary;
91 };
92 ic.services().get<o2::framework::CallbackService>().set<o2::framework::CallbackService::Id::Stop>(stop);
93
94 mMaxErrors = ic.options().get<int>("mid-checker-max-errors");
95 }
96
98 {
99 if (mChecker.getNEventsFaulty() >= mMaxErrors) {
100 // Abort checking: too many errors found
101 return;
102 }
103
104 auto tStart = std::chrono::high_resolution_clock::now();
105
106 auto msg = pc.inputs().getByPos(0);
107 auto data = o2::framework::DataRefUtils::as<const ROBoard>(msg);
108
109 auto msgROF = pc.inputs().getByPos(1);
110 auto inROFRecords = o2::framework::DataRefUtils::as<const ROFRecord>(msgROF);
111
112 std::vector<ROFRecord> dummy;
113 auto tAlgoStart = std::chrono::high_resolution_clock::now();
114 if (!mChecker.process(data, inROFRecords, dummy)) {
115 mOutFile << mChecker.getDebugMessage() << "\n";
116 }
117 mTimerAlgo += std::chrono::high_resolution_clock::now() - tAlgoStart;
118 mTimer += std::chrono::high_resolution_clock::now() - tStart;
119 }
120
121 private:
122 RAWCHECKER mChecker{};
123 std::vector<uint16_t> mFeeIds{};
124 CrateMasks mCrateMasks{};
125 ElectronicsDelay mElectronicsDelay{};
126 size_t mMaxErrors{0};
127 std::ofstream mOutFile{};
128 std::chrono::duration<double> mTimer{0};
129 std::chrono::duration<double> mTimerAlgo{0};
130};
131
132framework::DataProcessorSpec getRawCheckerSpec(const std::vector<uint16_t>& feeIds, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay, bool perGBT)
133{
134 std::vector<o2::framework::InputSpec> inputSpecs{o2::framework::InputSpec{"mid_decoded", header::gDataOriginMID, "DECODED", 0, o2::framework::Lifetime::Timeframe}, o2::framework::InputSpec{"mid_decoded_rof", header::gDataOriginMID, "DECODEDROF", 0, o2::framework::Lifetime::Timeframe}};
135
137 "MIDRawDataChecker",
138 {inputSpecs},
141 o2::framework::adaptFromTask<RawCheckerDeviceDPL<GBTRawDataChecker>>(feeIds, crateMasks, electronicsDelay)}
142 : o2::framework::adaptFromTask<RawCheckerDeviceDPL<RawDataChecker>>(feeIds, crateMasks, electronicsDelay),
143 o2::framework::Options{{"mid-checker-sync-trigger", o2::framework::VariantType::Int, 0x1, {"Trigger used for synchronisation (default is orbit 0x1)"}}, {"mid-checker-max-errors", o2::framework::VariantType::Int, 10000, {"Maximum number of errors"}}, {"mid-checker-outfile", o2::framework::VariantType::String, "", {"Checker output file"}}}};
144}
145
146} // namespace mid
147} // namespace o2
MID crate masks.
Data processor spec for MID raw checker device.
Class to check the raw data.
ServiceRegistryRef services()
Definition InitContext.h:34
ConfigParamRegistry const & options()
Definition InitContext.h:33
static DataRef getByPos(std::vector< InputRoute > const &routes, InputSpan const &span, int pos, int part=0)
InputRecord & inputs()
The inputs associated with this processing context.
uint8_t getMask(uint16_t feeId) const
Gets the mask for the feeId.
Definition CrateMasks.h:41
void init(o2::framework::InitContext &ic)
void run(o2::framework::ProcessingContext &pc)
RawCheckerDeviceDPL(const std::vector< uint16_t > &feeIds, const CrateMasks &crateMasks, const ElectronicsDelay &electronicsDelay)
GLboolean * data
Definition glcorearb.h:298
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
std::vector< ConfigParamSpec > Options
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getRawCheckerSpec(const std::vector< uint16_t > &feeIds, const CrateMasks &crateMasks, const ElectronicsDelay &electronicsDelay, bool perGBT=false)
std::string getSummary(const RAWCHECKER &checker, size_t maxErrors)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
uint64_t const void const *restrict const msg
Definition x9.h:153