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+ // \file Configuration.h
13+ // / \brief Utilities to describe FEE configuration
14+ // / \author wiktor.pierozak@cern.ch
15+
16+ #ifndef O2_FIT_FEE_CONFIGURATION
17+ #define O2_FIT_FEE_CONFIGURATION
18+
19+ #include < gsl/span>
20+ #include < cstddef>
21+ #include < cstdint>
22+ #include < limits>
23+ #include < type_traits>
24+ #include < algorithm>
25+ #include < Rtypes.h>
26+
27+ namespace o2 ::fit
28+ {
29+ namespace config_helpers
30+ {
31+ struct DefaultValueType {
32+ template <typename T>
33+ requires std::is_arithmetic_v<T>
34+ constexpr operator T () const noexcept
35+ {
36+ if constexpr (std::is_same_v<T, bool >) {
37+ return false ;
38+ } else {
39+ return std::numeric_limits<T>::max ();
40+ }
41+ }
42+ };
43+
44+ inline constexpr DefaultValueType DefaultValue{};
45+
46+ template <typename T, std::size_t N>
47+ constexpr void fillDefaultArray (T (&array)[N])
48+ {
49+ for (auto & element : array) {
50+ element = DefaultValue;
51+ }
52+ }
53+ } // namespace config_helpers
54+
55+ struct TcmConfig {
56+ float phaseDelayA{config_helpers::DefaultValue};
57+ float phaseDelayC{config_helpers::DefaultValue};
58+
59+ bool operator ==(const TcmConfig&) const = default ;
60+ ClassDefNV (TcmConfig, 1 );
61+ };
62+
63+ struct PmConfig {
64+ uint8_t orGate{config_helpers::DefaultValue};
65+ uint16_t trgChargeHighLevel{config_helpers::DefaultValue};
66+ uint16_t trgChargeLowLevel{config_helpers::DefaultValue};
67+ bool fddCoincidenceMode{config_helpers::DefaultValue};
68+ bool operator ==(const PmConfig&) const = default ;
69+ ClassDefNV (PmConfig, 1 );
70+ };
71+
72+ template <int NChannels>
73+ struct ChannelsConfig {
74+ int16_t timeAlignments[NChannels];
75+ uint16_t cfdThresholds[NChannels];
76+ int16_t cfdZeros[NChannels];
77+ int16_t adcZeros[NChannels];
78+ uint16_t adcDelays[NChannels];
79+ uint16_t rangeCorrectionAdc0[NChannels];
80+ uint16_t rangeCorrectionAdc1[NChannels];
81+ uint16_t thresholdCalibration[NChannels];
82+ bool channelMaskData[NChannels];
83+ bool channelMaskTriggers[NChannels];
84+
85+ constexpr ChannelsConfig ()
86+ {
87+ config_helpers::fillDefaultArray (timeAlignments);
88+ config_helpers::fillDefaultArray (cfdThresholds);
89+ config_helpers::fillDefaultArray (cfdZeros);
90+ config_helpers::fillDefaultArray (adcZeros);
91+ config_helpers::fillDefaultArray (adcDelays);
92+ config_helpers::fillDefaultArray (rangeCorrectionAdc0);
93+ config_helpers::fillDefaultArray (rangeCorrectionAdc1);
94+ config_helpers::fillDefaultArray (channelMaskData);
95+ config_helpers::fillDefaultArray (channelMaskTriggers);
96+ config_helpers::fillDefaultArray (thresholdCalibration);
97+ }
98+
99+ template <typename T>
100+ [[nodiscard]] static constexpr bool isDefault (const T& value)
101+ {
102+ return value == static_cast <T>(config_helpers::DefaultValue);
103+ }
104+
105+ gsl::span<const int16_t , NChannels> getTimeAlignments () const { return timeAlignments; }
106+ gsl::span<const uint16_t , NChannels> getCfdThresholds () const { return cfdThresholds; }
107+ gsl::span<const int16_t , NChannels> getCfdZeros () const { return cfdZeros; }
108+ gsl::span<const int16_t , NChannels> getAdcZeros () const { return adcZeros; }
109+ gsl::span<const uint16_t , NChannels> getAdcDelays () const { return adcDelays; }
110+ gsl::span<const uint16_t , NChannels> getRangeCorrectionAdc0 () const { return rangeCorrectionAdc0; }
111+ gsl::span<const uint16_t , NChannels> getRangeCorrectionAdc1 () const { return rangeCorrectionAdc1; }
112+ gsl::span<const uint16_t , NChannels> getThresholdCalibration () const { return thresholdCalibration; }
113+ gsl::span<const bool , NChannels> getChannelMaskTriggers () const { return channelMaskTriggers; }
114+ gsl::span<const bool , NChannels> getChannelMaskData () const { return channelMaskData; }
115+
116+ bool operator ==(const ChannelsConfig& other) const
117+ {
118+ return std::equal (std::begin (timeAlignments), std::end (timeAlignments), std::begin (other.timeAlignments )) &&
119+ std::equal (std::begin (cfdThresholds), std::end (cfdThresholds), std::begin (other.cfdThresholds )) &&
120+ std::equal (std::begin (cfdZeros), std::end (cfdZeros), std::begin (other.cfdZeros )) &&
121+ std::equal (std::begin (adcZeros), std::end (adcZeros), std::begin (other.adcZeros )) &&
122+ std::equal (std::begin (adcDelays), std::end (adcDelays), std::begin (other.adcDelays )) &&
123+ std::equal (std::begin (rangeCorrectionAdc0), std::end (rangeCorrectionAdc0), std::begin (other.rangeCorrectionAdc0 )) &&
124+ std::equal (std::begin (rangeCorrectionAdc1), std::end (rangeCorrectionAdc1), std::begin (other.rangeCorrectionAdc1 )) &&
125+ std::equal (std::begin (thresholdCalibration), std::end (thresholdCalibration), std::begin (other.thresholdCalibration )) &&
126+ std::equal (std::begin (channelMaskData), std::end (channelMaskData), std::begin (other.channelMaskData )) &&
127+ std::equal (std::begin (channelMaskTriggers), std::end (channelMaskTriggers), std::begin (other.channelMaskTriggers ));
128+ }
129+
130+ ClassDefNV (ChannelsConfig<NChannels>, 1 );
131+ };
132+
133+ template <std::size_t NChannels>
134+ struct HvChannelsConfig {
135+ float gain[NChannels];
136+
137+ constexpr HvChannelsConfig ()
138+ {
139+ config_helpers::fillDefaultArray (gain);
140+ }
141+ bool operator ==(const HvChannelsConfig& other) const
142+ {
143+ return std::equal (std::begin (gain), std::end (gain), std::begin (other.gain ));
144+ }
145+ ClassDefNV (HvChannelsConfig<NChannels>, 1 );
146+ };
147+ } // namespace o2::fit
148+ #endif
0 commit comments