CbmRoot
Loading...
Searching...
No Matches
CbmTrdRawMessageSpadic.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
6
7#include <algorithm> // for max_element
8#include <cstdint>
9#include <stdexcept> // for range_error
10
11#include "AlgoFairloggerCompat.h" // for LOG
12
13// ------- Default Constructor ----------------
15 : fChannelID()
16 , fElinkID()
17 , fCrobId()
18 , fCriId()
19 , fHitType()
20 , fNrSamples()
21 , fMultiHit()
22 , fFullTime()
23 , fSamples()
24{
25}
26
27// ------- Constructor ----------------
28CbmTrdRawMessageSpadic::CbmTrdRawMessageSpadic(uint8_t channelId, uint8_t elinkId, uint8_t crobId, uint16_t criId,
29 uint8_t hitType, uint8_t nrSamples, bool multiHit, uint64_t fullTime,
30 std::vector<int16_t> samples)
31 : fChannelID{channelId}
32 , fElinkID{elinkId}
33 , fCrobId(crobId)
34 , fCriId{criId}
35 , fHitType{hitType}
36 , fNrSamples{nrSamples}
37 , fMultiHit{multiHit}
38 , fFullTime{fullTime}
39 , fSamples(samples)
40{
41 // throw an exception if samples has more than 32 elements.
42 if (fSamples.size() > 32) {
43 LOG(error) << "CbmTrdRawMessageSpadic: too many samples in message!";
44 throw std::range_error("CbmTrdRawMessageSpadic: too many samples in message!");
45 }
46}
47
48// ------- copy Constructor ----------------
61
62// ------- Destructor ----------------
64
66{
67 int16_t maxADC = *std::max_element(fSamples.begin(), fSamples.end());
68
69 return maxADC;
70}
71
72void CbmTrdRawMessageSpadic::SetSample(int16_t value, uint8_t pos)
73{
74 if (pos > 31 || value < -256 || value > 256 || pos >= fNrSamples) {
75 LOG(error) << "CbmTrdRawMessageSpadic::SetSample() pos = " << static_cast<uint16_t>(pos)
76 << " fNrSamples = " << static_cast<uint16_t>(fNrSamples) << " value = " << value
77 << " so we are out of range!";
78 return;
79 }
80 if ((uint8_t)(pos + 1) > fSamples.size()) {
81 fSamples.resize(pos + 1);
82 }
83 fSamples.at(pos) = value;
84
85 return;
86}
void SetSample(int16_t value, uint8_t pos)
std::vector< int16_t > fSamples