GCC Code Coverage Report


Directory: ./
File: include/na64detID/TBNameErrors.hh
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 8 14 57.1%
Functions: 2 4 50.0%
Branches: 1 1 100.0%

Line Branch Exec Source
1 /* This file is a part of NA64SW software.
2 * Copyright (C) 2015-2022 NA64 Collaboration, CERN
3 *
4 * NA64SW is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #pragma once
18
19 #include "na64util/str-fmt.hh"
20
21 #include <cstring>
22
23 /**\file
24 *
25 * \brief Errors related to detector name/detector ID conversions.
26 *
27 * Contains declaration of the exceptions thrown by `DetectorNaming` class.
28 * */
29
30 namespace na64dp {
31 namespace errors {
32 /// \brief Insertion failure exception class -- invalid ID provided with user
33 /// input.
34 class IDIsOutOfRange : public std::runtime_error {
35 private:
36 int _proposedID;
37 int _maximumValue;
38 public:
39 IDIsOutOfRange( const char * what_, int proposed, int maximum ) throw();
40 int proposed_id() const throw() { return _proposedID; }
41 int max_id() const throw() { return _maximumValue; }
42 };
43
44 /// \brief Insertion failure exception class. Proposed chip/kin/detector name
45 /// is not unique.
46 class NameIsNotUniq : public std::runtime_error {
47 private:
48 char _name[64];
49 public:
50 NameIsNotUniq( const char * what_, const char * nm_ ) throw();
51 const char * name() const throw() { return _name; }
52 };
53
54 /// \brief Insertion failure exception class. Proposed detector ID is not
55 /// unique.
56 class IDIsNotUniq : public std::runtime_error {
57 private:
58 int _proposedID;
59 public:
60 IDIsNotUniq( const char * what_, int proposed_ ) throw()
61 : std::runtime_error(what_), _proposedID(proposed_) {}
62 int proposed_id() const throw() { return _proposedID; }
63 };
64
65 ///\brief A TBname decoding failure exception class.
66 class TBNameParsingFailure : public std::runtime_error {
67 private:
68 char _TBName[64];
69 public:
70 TBNameParsingFailure(const char * msg, const char * culprit_) throw();
71 const char * culprit() const throw() { return _TBName; }
72 };
73
74 class UnknownKin : public TBNameParsingFailure {
75 public:
76 std::string base;
77 UnknownKin( const std::string & base_
78 , const char * culprit_) throw() : TBNameParsingFailure(
79 (std::string("Base name \"") + base_ + "\" does not refer to known kin.").c_str()
80 , culprit_ )
81 , base(base_) {}
82 };
83
84 /// \brief Detector name and/or the additional information is not complete
85 /// or not valid to identify the detector ID.
86 ///
87 /// Raised by postfix conversion procedures.
88 class IncompleteDetectorName : public std::runtime_error {
89 private:
90 char _culprit[32];
91 public:
92 IncompleteDetectorName( const char * whatStr, const char * name )
93 : std::runtime_error(whatStr) {
94 strncpy(_culprit, name, sizeof(_culprit));
95 }
96 /// Returns string name that caused this exception.
97 const char * culprit() const throw() {
98 return _culprit;
99 }
100 };
101
102 /// \brief At least one failed substitution during name formatting
103 ///
104 /// Raised by ID-to-string conversion methods, if any curly bracket character
105 /// remains after substitution
106 class IncompleteDetectorID : public std::runtime_error {
107 private:
108 char _template[64]
109 , _formatted[64]
110 ;
111 public:
112 1 IncompleteDetectorID( const char * templateStr
113 , const char * formattedStr )
114 1 : std::runtime_error( util::format("Detector name string pattern \"%s\" is"
115 " incomplete after substitution: \"%s\""
116 , templateStr
117
1/1
✓ Branch 3 taken 1 times.
1 , formattedStr).c_str() ) {
118 1 strncpy(_template, templateStr, sizeof(_template));
119 1 strncpy(_formatted, formattedStr, sizeof(_formatted));
120 1 }
121 /// Returns string name that caused this exception.
122 const char * template_str() const throw() {
123 return _template;
124 }
125 const char * formatted_str() const throw() {
126 return _formatted;
127 }
128 };
129
130 /// \brief No converters entry exists, but postfix is provided.
131 class NoMappingDefined : public std::runtime_error {
132 public:
133 NoMappingDefined( const char * whatStr ) : std::runtime_error(whatStr) {}
134 };
135
136 ///\brief Thrown when no entry is defined for key.
137 template<typename T>
138 class NoEntryForKey : public std::runtime_error {
139 private:
140 T _culprit;
141 public:
142 1 NoEntryForKey(const char * msg, const T & culprit_) throw()
143 : std::runtime_error( msg )
144 1 , _culprit(culprit_) {}
145 const T & culprit() const throw() { return _culprit; }
146 };
147
148 } // namespace na64dp::errors
149 } // namespace na64dp
150
151