Project
Loading...
Searching...
No Matches
mask-maker.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
17#include <iostream>
18#include <vector>
19#include "boost/program_options.hpp"
24#include "MIDRaw/CrateMasks.h"
26#include "MIDRaw/Decoder.h"
28#include "MIDRaw/FEEIdConfig.h"
35
36namespace po = boost::program_options;
37
38bool processScalers(const o2::mid::ChannelScalers& scalers, unsigned long nEvents, double threshold, const std::vector<o2::mid::ColumnData>& refMasks, const char* outFilename)
39{
40 auto masks = o2::mid::makeMasks(scalers, nEvents, threshold, refMasks);
41 if (masks.empty()) {
42 std::cout << "No problematic digit found" << std::endl;
43 return true;
44 }
45
46 std::cout << "Problematic digits found. Corresponding masks:" << std::endl;
47 for (auto& mask : masks) {
48 std::cout << mask << std::endl;
49 }
50
52 o2::mid::ROBoardConfigHandler roBoardCfgHandler;
53
54 std::cout << "\nCorresponding boards masks:" << std::endl;
55 colToBoard.process(masks);
56 auto roMasks = colToBoard.getData();
57 for (auto& board : roMasks) {
58 std::cout << board << std::endl;
59 }
60 std::cout << "\nMask file produced: " << outFilename << std::endl;
62 masksHandler.setFromChannelMasks(masks);
63 masksHandler.merge(o2::mid::makeDefaultMasks());
64 colToBoard.process(masksHandler.getMasks());
65 roBoardCfgHandler.updateMasks(colToBoard.getData());
66 roBoardCfgHandler.write(outFilename);
67 return false;
68}
69
70int main(int argc, char* argv[])
71{
72 po::variables_map vm;
73 po::options_description generic("Generic options");
74
75 // clang-format off
76 generic.add_options()
77 ("help", "produce help message")
78 ("feeId-config-file", po::value<std::string>(),"Filename with crate FEE ID correspondence")
79 ("crate-masks-file", po::value<std::string>(),"Filename with crate masks")
80 ("electronics-delay-file", po::value<std::string>(),"Filename with electronics delay")
81 ("occupancy-threshold", po::value<double>()->default_value(0.9),"Occupancy threshold");
82
83
84 po::options_description hidden("hidden options");
85 hidden.add_options()
86 ("input", po::value<std::vector<std::string>>(),"Input filename");
87 // clang-format on
88
89 po::options_description cmdline;
90 cmdline.add(generic).add(hidden);
91
92 po::positional_options_description pos;
93 pos.add("input", -1);
94
95 po::store(po::command_line_parser(argc, argv).options(cmdline).positional(pos).run(), vm);
96 po::notify(vm);
97
98 if (vm.count("help")) {
99 std::cout << "Usage: " << argv[0] << " <input_raw_filename> [input_raw_filename_1 ...]\n";
100 std::cout << generic << std::endl;
101 return 2;
102 }
103 if (vm.count("input") == 0) {
104 std::cout << "no input file specified" << std::endl;
105 return 1;
106 }
107
108 std::vector<std::string> inputfiles{vm["input"].as<std::vector<std::string>>()};
109
110 std::unique_ptr<o2::mid::Decoder> decoder{nullptr};
111
112 o2::mid::FEEIdConfig feeIdConfig;
113 if (vm.count("feeId-config-file")) {
114 feeIdConfig = o2::mid::FEEIdConfig(vm["feeId-config-file"].as<std::string>().c_str());
115 }
116
117 o2::mid::ElectronicsDelay electronicsDelay;
118 if (vm.count("electronics-delay-file")) {
119 electronicsDelay = o2::mid::readElectronicsDelay(vm["electronics-delay-file"].as<std::string>().c_str());
120 }
121
122 o2::mid::CrateMasks crateMasks;
123 if (vm.count("crate-masks-file")) {
124 crateMasks = o2::mid::CrateMasks(vm["crate-masks-file"].as<std::string>().c_str());
125 }
126
127 auto threshold = vm["occupancy-threshold"].as<double>();
128
129 std::vector<o2::mid::ROBoard> data;
130 std::vector<o2::mid::ROFRecord> rofRecords;
131
132 for (auto& filename : inputfiles) {
133 o2::mid::RawFileReader rawFileReader;
134 if (!rawFileReader.init(filename.c_str())) {
135 return 2;
136 }
137
138 while (rawFileReader.readHB() > 0) {
139 if (!decoder) {
140 auto const* rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(rawFileReader.getData().data());
141 decoder = o2::mid::createDecoder(*rdhPtr, false, electronicsDelay, crateMasks, feeIdConfig);
142 }
143 decoder->process(rawFileReader.getData());
144 rawFileReader.clear();
145 size_t offset = data.size();
146 data.insert(data.end(), decoder->getData().begin(), decoder->getData().end());
147 for (auto& rof : decoder->getROFRecords()) {
148 rofRecords.emplace_back(rof.interactionRecord, rof.eventType, rof.firstEntry + offset, rof.nEntries);
149 }
150 }
151 }
152
154 aggregator.process(data, rofRecords);
155 std::array<o2::mid::ChannelScalers, 2> scalers;
156 for (auto& noisy : aggregator.getData(o2::mid::EventType::Calib)) {
157 scalers[0].count(noisy);
158 }
159
160 unsigned long nEvents = aggregator.getROFRecords(o2::mid::EventType::Calib).size();
161 auto refMasks = makeDefaultMasksFromCrateConfig(feeIdConfig, crateMasks);
162
163 bool isOk = true;
164 std::cout << "\nCHECKING NOISY CHANNELS:" << std::endl;
165 isOk &= processScalers(scalers[0], nEvents, threshold, refMasks, "calib_mask.txt");
166
167 o2::mid::FetToDead fetToDead;
168 fetToDead.setMasks(refMasks);
169 auto fetRofs = aggregator.getROFRecords(o2::mid::EventType::FET);
170 auto fets = aggregator.getData(o2::mid::EventType::FET);
171
172 for (auto& rof : fetRofs) {
173 std::vector<o2::mid::ColumnData> eventFets(fets.begin() + rof.firstEntry, fets.begin() + rof.getEndIndex());
174 auto deadChannels = fetToDead.process(eventFets);
175 for (auto& dead : deadChannels) {
176 scalers[1].count(dead);
177 }
178 }
179 std::cout << "\nCHECKING DEAD CHANNELS:" << std::endl;
180 isOk &= processScalers(scalers[1], nEvents, threshold, refMasks, "FET_mask.txt");
181
182 return isOk ? 0 : 1;
183}
MID channels masks handler.
MID channel scalers.
Converter from ColumnData to raw local boards.
MID crate masks.
MID decoded raw data aggregator.
MID raw data decoder.
Delay parameters for MID electronics.
Hardware Id to FeeId mapper.
Class to convert the FEE test event into dead channels.
MID raw file reader.
Definition of the MID event record.
Function to produce the MID masks.
Structure to store the readout board information.
uint16_t pos
Definition RawData.h:3
std::vector< ColumnData > getMasks() const
Gets the masks.
void setFromChannelMasks(const std::vector< ColumnData > &masks)
void merge(const std::vector< ColumnData > &masks)
std::vector< ROBoard > getData() const
Gets vector of ROBoard.
void process(gsl::span< const ColumnData > data, bool allowEmpty=false)
const std::vector< ROFRecord > & getROFRecords(EventType eventType=EventType::Standard)
Gets the vector of data RO frame records.
void process(gsl::span< const ROBoard > localBoards, gsl::span< const ROFRecord > rofRecords)
const std::vector< ColumnData > & getData(EventType eventType=EventType::Standard)
Gets the vector of data.
std::vector< ColumnData > process(gsl::span< const ColumnData > fetData)
Definition FetToDead.cxx:51
void setMasks(const std::vector< ColumnData > &masks)
Sets the masks.
Definition FetToDead.h:44
void write(const char *filename) const
void updateMasks(const std::vector< ROBoard > &masks)
bool readHB(bool sendCompleteHBs=false)
const std::vector< uint8_t > & getData()
Gets the vector of data.
bool init(const char *inFilename, bool readContinuous=false)
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLint GLuint mask
Definition glcorearb.h:291
bool processScalers(const o2::mid::ChannelScalers &scalers, unsigned long nEvents, double threshold, const std::vector< o2::mid::ColumnData > &refMasks, const char *outFilename)
std::vector< ColumnData > makeDefaultMasks()
Definition MaskMaker.cxx:62
std::vector< ColumnData > makeMasks(const ChannelScalers &scalers, double timeOrTriggers, double threshold, const std::vector< ColumnData > &refMasks={})
Definition MaskMaker.cxx:43
std::unique_ptr< Decoder > createDecoder(const o2::header::RDHAny &rdh, bool isDebugMode, const ElectronicsDelay &electronicsDelay, const CrateMasks &crateMasks, const FEEIdConfig &feeIdConfig)
Definition Decoder.cxx:63
ElectronicsDelay readElectronicsDelay(const char *filename)
std::string filename()
const int nEvents
Definition test_Fifo.cxx:27
#define main