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(std::uint8_t channelId, std::uint8_t elinkId, std::uint8_t crobId,
29 std::uint16_t criId, std::uint8_t hitType, std::uint8_t nrSamples,
30 bool multiHit, std::uint64_t fullTime, std::vector<std::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 ----------------
50 : fChannelID {old.fChannelID}
51 , fElinkID {old.fElinkID}
52 , fCrobId(old.fCrobId)
53 , fCriId {old.fCriId}
54 , fHitType {old.fHitType}
55 , fNrSamples {old.fNrSamples}
56 , fMultiHit {old.fMultiHit}
57 , fFullTime {old.fFullTime}
58 , fSamples(old.fSamples)
59{
60}
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(std::int16_t value, std::uint8_t pos)
73{
74 if (pos > 31 || value < -256 || value > 256 || pos >= fNrSamples) {
75 LOG(error) << "CbmTrdRawMessageSpadic::SetSample() pos = " << static_cast<std::uint16_t>(pos)
76 << " fNrSamples = " << static_cast<std::uint16_t>(fNrSamples) << " value = " << value
77 << " so we are out of range!";
78 return;
79 }
80 if ((std::uint8_t)(pos + 1) > fSamples.size()) { fSamples.resize(pos + 1); }
81 fSamples.at(pos) = value;
82
83 return;
84}
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
void SetSample(std::int16_t value, std::uint8_t pos)
std::vector< std::int16_t > fSamples