forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherrors.cpp
More file actions
59 lines (50 loc) · 1.5 KB
/
errors.cpp
File metadata and controls
59 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "Acts/TrackFitting/KalmanFitterError.hpp"
#include "Acts/Utilities/Result.hpp"
#include <iostream>
#include <system_error>
// Example struct representing a track for demonstration purposes
struct Track {
int id;
};
// Example struct representing track parameters
struct TrackParameters {
double momentum;
};
//! [Error Enum Pattern]
enum class MyComponentError {
ErrorValue1 = 1, // All error values must be non-zero
ErrorValue2,
// ...
};
// Factory function to create std::error_code
std::error_code make_error_code(MyComponentError e);
//! [Error Enum Pattern]
//! [Usage with Result Type]
Acts::Result<Track> fitTrack(const TrackParameters& params) {
if (params.momentum < 0) {
return Acts::KalmanFitterError::UpdateFailed;
}
Track track{42};
return track; // Success
}
void processTrack() {
TrackParameters params{100.0};
// Usage
auto result = fitTrack(params);
if (!result.ok()) {
std::error_code error = result.error();
// Handle error
std::cerr << "Error: " << error.message() << std::endl;
} else {
Track track = std::move(result).value();
std::cout << "Track fitted successfully: " << track.id << std::endl;
}
}
//! [Usage with Result Type]