Project
Loading...
Searching...
No Matches
testPadIndices.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
12#include "InputDocument.h"
13#include <string>
14#include <iostream>
15#include <fmt/format.h>
17#include <boost/program_options.hpp>
18#include <vector>
19#include <fstream>
20
21namespace po = boost::program_options;
22
23std::string asString(rapidjson::Value& tp)
24{
25 //got =FEC 229CH 25X 19Y 20SX 2.5SY 0.5 (B)
26 return fmt::format("FEC {} CH {} padindex {} bending {} X {} Y {}",
27 tp["dsid"].GetInt(),
28 tp["dsch"].GetInt(),
29 tp["padindex"].GetInt(), tp["bending"].GetString(), tp["x"].GetDouble(),
30 tp["y"].GetDouble());
31}
32
33int CheckPadIndexIsAsExpected(std::string filepath)
34{
35 InputWrapper data(filepath.c_str());
36
37 rapidjson::Value& padIndices = data.document()["channels"];
38
39 int nbad{0};
40 int ntested{0};
41
42 for (auto& tp : padIndices.GetArray()) {
43 ntested++;
44 int detElemId = tp["de"].GetInt();
45 bool isBendingPlane = (tp["bending"].GetString() == std::string("true"));
46 int refPadIndex = tp["padindex"].GetInt();
47 const auto& seg = o2::mch::mapping::segmentation(detElemId);
48 int bpad;
49 int nbpad;
50 seg.findPadPairByPosition(tp["x"].GetDouble(), tp["y"].GetDouble(), bpad, nbpad);
51 int padIndex = (isBendingPlane ? bpad : nbpad);
52 if (padIndex != refPadIndex) {
53 nbad++;
54 std::cout << fmt::format(">>> {} : Expected index = {} but got {}\n", filepath.c_str(), refPadIndex, padIndex);
55 std::cout << "expected=" << seg.padAsString(refPadIndex) << "\n";
56 std::cout << "got =" << seg.padAsString(padIndex) << "\n";
57 std::cout << "b =" << seg.padAsString(bpad) << "\n";
58 std::cout << "nb =" << seg.padAsString(nbpad) << "\n";
59 }
60 }
61
62 if (nbad) {
63 std::cout << fmt::format("\n{} : {} pad indices error(s) over {} tested pads\n\n", filepath.c_str(), nbad, ntested);
64 } else {
65 std::cout << fmt::format("\n{} : the indices of all tested {} pads are OK\n\n", filepath.c_str(), ntested);
66 }
67 return nbad;
68}
69
70int main(int argc, char** argv)
71{
72 std::string filePattern;
73 std::vector<int> deIds;
74 po::variables_map vm;
75 po::options_description generic("Generic options");
76
77 // clang-format off
78 generic.add_options()
79 ("help,h", "produce help message")
80 ("filepattern,p", po::value<std::string>(&filePattern)->required(), "input file pattern")
81 ("de,d",po::value<std::vector<int>>(&deIds)->multitoken(),"detection element")
82 ;
83 // clang-format on
84
85 po::options_description cmdline;
86 cmdline.add(generic);
87
88 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
89
90 if (vm.count("help")) {
91 std::cout << generic << "\n";
92 return 2;
93 }
94
95 try {
96 po::notify(vm);
97 } catch (boost::program_options::error& e) {
98 std::cout << "Error: " << e.what() << "\n";
99 exit(1);
100 }
101
102 int nbad{0};
103
104 for (auto de : deIds) {
105 std::string filepath(fmt::format(fmt::runtime(filePattern), de));
106 std::ifstream in(filepath);
107 if (!in) {
108 std::cout << "Cannot open " << filepath << "\n";
109 return -1;
110 }
111 nbad += CheckPadIndexIsAsExpected(filepath);
112 }
113 return nbad != 0;
114}
bool isBendingPlane
o2::mch::mapping::CathodeSegmentation seg
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
std::string padAsString(int catPadIndex) const
GLboolean * data
Definition glcorearb.h:298
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
int CheckPadIndexIsAsExpected(std::string filepath)
std::string asString(rapidjson::Value &tp)
uint16_t de
#define main