AnalysisTree
Loading...
Searching...
No Matches
Detector.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen, MEPhI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Eugeny Kashirin, Ilya Selyuzhenkov */
4#ifndef ANALYSISTREE_GENERICCHANNELDETECTOR_H
5#define ANALYSISTREE_GENERICCHANNELDETECTOR_H
6
7#include "IndexedObject.hpp"
8
9#include "Hit.hpp"
10#include "Module.hpp"
11#include "Particle.hpp"
12#include "Track.hpp"
13
14namespace AnalysisTree {
20template<class T>
21class Detector : public IndexedObject, protected IndexAccessor {
22
23 public:
24 static_assert(std::is_nothrow_move_constructible<std::vector<T>>::value,
25 "std::vector<T> is expected to be copy-constructible");
26 static_assert(std::is_nothrow_move_assignable<std::vector<T>>::value,
27 "std::vector<T> is expected to be copy-assignable");
28
29 Detector() = default;
30 explicit Detector(size_t id) : IndexedObject(id) {}
31 Detector(const Detector& otherDetector) = default;
32 Detector(Detector&& otherDetector) noexcept = default;
33 Detector& operator=(Detector&&) noexcept = default;
34 Detector& operator=(const Detector& part) = default;
35
36 ~Detector() override = default;
37
38 ANALYSISTREE_ATTR_NODISCARD size_t GetNumberOfChannels() const noexcept {
39 return channels_.size();
40 }
41
42 // ANALYSISTREE_ATTR_DEPRECATED("Please use: T& AddChannel(const BranchConfig& branch)")
43 T* AddChannel() {
44 channels_.emplace_back(T(channels_.size()));
45 return &(channels_.back());
46 }
47
48 T& AddChannel(const BranchConfig& branch) {
49 channels_.emplace_back(T(channels_.size(), branch));
50 return channels_.back();
51 }
52
53 void ClearChannels() {
54 channels_.clear();
55 }
56
57 T& Channel(size_t number)// needed in converter to modify tracks id
58 {
59 if (number < GetNumberOfChannels()) {
60 return channels_.at(number);
61 } else {
62 throw std::out_of_range("Detector::Channel - wrong channel number " + std::to_string(number) + " Number of channels in this detector is " + std::to_string(GetNumberOfChannels()));
63 }
64 }
65
66 const T& GetChannel(size_t number) const {
67 if (number < GetNumberOfChannels()) {
68 return channels_.at(number);
69 } else {
70 throw std::out_of_range("Detector::GetChannel - wrong channel number " + std::to_string(number) + " Number of channels in this detector is " + std::to_string(GetNumberOfChannels()));
71 }
72 }
73
74 friend bool operator==(const Detector& that, const Detector& other) {
75 if (&that == &other) {
76 return true;
77 }
78
79 if ((IndexedObject&) that != (IndexedObject&) other) {
80 return false;
81 }
82
83 return std::equal(that.channels_.begin(), that.channels_.end(), other.channels_.begin());
84 }
85
86 ANALYSISTREE_ATTR_DEPRECATED("Please use range-based loops: for(const auto& channel : detector)")
87 const std::vector<T>* GetChannels() const { return &channels_; }
88 ANALYSISTREE_ATTR_DEPRECATED("Please use range-based loops: for(const auto& channel : detector)")
89 std::vector<T>* Channels() { return &channels_; }
90
91 void Reserve(size_t n) {
92 channels_.reserve(n);
93 }
94
95 void Print() const {
96 for (const auto& channel : channels_) {
97 channel.Print();
98 }
99 }
100
101 auto begin() -> typename std::vector<T>::iterator { return channels_.begin(); }
102 auto end() -> typename std::vector<T>::iterator { return channels_.end(); }
103 auto cbegin() const -> typename std::vector<T>::const_iterator { return channels_.begin(); }
104 auto cend() const -> typename std::vector<T>::const_iterator { return channels_.end(); }
105 auto begin() const -> typename std::vector<T>::const_iterator { return channels_.begin(); }
106 auto end() const -> typename std::vector<T>::const_iterator { return channels_.end(); }
107
108 protected:
109 std::vector<T> channels_{};
110
111 ClassDefOverride(Detector, 2)
112};
113
120
121}// namespace AnalysisTree
122
123#endif//ANALYSISTREE_GENERICCHANNELDETECTOR_H
A class to store configuration of the Container.
Definition BranchConfig.hpp:118
Definition Detector.hpp:21
Definition IndexedObject.hpp:18
Definition IndexedObject.hpp:30
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10