Project
Loading...
Searching...
No Matches
SanityCheck.h
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#ifndef O2_MCH_BASE_SANITY_CHECK_H
13#define O2_MCH_BASE_SANITY_CHECK_H
14
16#include "Framework/Logger.h"
17#include <gsl/span>
18#include <map>
19#include <string>
20#include <vector>
21
22namespace o2::mch
23{
24struct Pad {
25 int detId;
26 int padId;
27
28 bool operator<(const Pad& other) const
29 {
30 if (detId == other.detId) {
31 return padId < other.padId;
32 }
33 return detId < other.detId;
34 }
35};
36
38 uint32_t nofDuplicatedItems{0};
40 uint32_t nofMissingItems{0};
41 uint32_t nofOutOfBounds{0};
42};
43
44bool isOK(const SanityError& error);
45std::string asString(const SanityError& error);
46
47template <typename T>
48SanityError sanityCheck(gsl::span<const ROFRecord> rofs, gsl::span<const T> items)
49{
50 // check that :
51 // - all items indices are used in rofs
52 // - each item is referenced only once
53 // - all indices used in rofs are inbound of items.size()
54
55 SanityError error;
56
57 std::vector<int> indices;
58 indices.resize(items.size());
59
60 for (const auto& r : rofs) {
61 std::map<T, int> itemMap;
62 for (auto i = r.getFirstIdx(); i <= r.getLastIdx(); i++) {
63 if (i >= items.size()) {
64 error.nofOutOfBounds++;
65 continue;
66 }
67 indices[i]++;
68 const auto& item = items[i];
69 itemMap[item]++;
70 }
71 if (itemMap.size() != r.getNEntries()) {
72 error.nofDuplicatedItems += (r.getNEntries() - itemMap.size());
73 }
74 }
75 for (auto i = 0; i < indices.size(); i++) {
76 if (indices[i] == 0) {
77 error.nofMissingItems++;
78 }
79 if (indices[i] > 1) {
81 }
82 }
83
84 return error;
85}
86} // namespace o2::mch
87
88#endif
int32_t i
Definition of the MCH ROFrame record.
GLsizei GLenum const void * indices
Definition glcorearb.h:400
GLboolean r
Definition glcorearb.h:1233
std::string asString(const o2::mch::TrackMCH &t)
Definition TrackMCH.cxx:104
bool isOK(const SanityError &error)
SanityError sanityCheck(gsl::span< const ROFRecord > rofs, gsl::span< const T > items)
Definition SanityCheck.h:48
bool operator<(const Pad &other) const
Definition SanityCheck.h:28
uint32_t nofDuplicatedItems
Definition SanityCheck.h:38
uint32_t nofDuplicatedIndices
Definition SanityCheck.h:39
VectorOfTObjectPtrs other