Project
Loading...
Searching...
No Matches
SampaCluster.cxx
Go to the documentation of this file.
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
14#include "Assertions.h"
15#include <fmt/format.h>
16#include <sstream>
17
18namespace o2
19{
20namespace mch
21{
22namespace raw
23{
24
26 : sampaTime(impl::assertIsInRange("sampaTime", sampaTime, 0, 0x3FF)),
27 bunchCrossing(impl::assertIsInRange("bunchCrossing", bunchCrossing, 0, 0xFFFFF)),
28 chargeSum(impl::assertIsInRange("chargeSum", chargeSum, 0, 0xFFFFF)), // 20 bits
29 clusterSize(impl::assertIsInRange("clusterSize", clusterSize, 0, 0x3FF)), // 10 bits
30 samples{}
31
32{
33}
34
35SampaCluster::SampaCluster(uint10_t sampaTime, uint20_t bunchCrossing, const std::vector<uint10_t>& samples)
36 : sampaTime(impl::assertIsInRange("sampaTime", sampaTime, 0, 0x3FF)),
37 bunchCrossing(impl::assertIsInRange("bunchCrossing", bunchCrossing, 0, 0xFFFFF)),
38 chargeSum(0),
39 clusterSize(impl::assertIsInRange("clusterSize", samples.size(), 0, 0x3FF)), // 10 bits
40 samples(samples.begin(), samples.end())
41{
42 if (samples.empty()) {
43 throw std::invalid_argument("cannot add data with no sample");
44 }
45 for (auto i = 0; i < samples.size(); i++) {
46 impl::assertIsInRange("sample", samples[i], 0, 0x3FF);
47 }
48}
49
51{
52 if (!samples.empty()) {
53 return samples.size();
54 }
55 return clusterSize;
56}
57
59{
60 return samples.empty();
61}
62
64{
65 uint16_t n10{2}; // 10 bits (nsamples) + 10 bits (sampaTime)
66 if (isClusterSum()) {
67 n10 += 2; // 20 bits (chargesum)
68 } else {
69 n10 += samples.size();
70 }
71 return n10;
72}
73
75{
76 uint32_t tot(0);
77 if (isClusterSum()) {
78 tot = chargeSum;
79 } else {
80 for (const auto& s : samples) {
81 tot += s;
82 }
83 }
84
85 return tot;
86}
87
88std::ostream& operator<<(std::ostream& os, const SampaCluster& sc)
89{
90 os << fmt::format("ts {:4d} ", sc.sampaTime);
91 os << fmt::format("bc {:4d} ", sc.bunchCrossing);
92 os << fmt::format("cs {:4d} ", sc.nofSamples());
93 if (sc.isClusterSum()) {
94 os << fmt::format("q {:6d}", sc.chargeSum);
95 } else {
96 os << fmt::format("n {:4d} q [ ", sc.samples.size());
97 for (auto s : sc.samples) {
98 os << fmt::format("{:4d} ", s);
99 }
100 os << "]";
101 }
102 return os;
103}
104
105std::string asString(const SampaCluster& sc)
106{
107 std::string s = fmt::format("ts-{}-bc-{}-cs-{}-q", sc.sampaTime, sc.bunchCrossing, sc.nofSamples());
108 if (sc.isClusterSum()) {
109 s += fmt::format("-{}", sc.chargeSum);
110 } else {
111 for (auto sample : sc.samples) {
112 s += fmt::format("-{}", sample);
113 }
114 }
115 return s;
116}
117
118} // namespace raw
119} // namespace mch
120} // namespace o2
unsigned short int uint16_t
int32_t i
o2::raw::RawFileWriter * raw
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
int clusterSize
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLsizei samples
Definition glcorearb.h:1309
int assertIsInRange(std::string what, uint64_t value, uint64_t min, uint64_t max)
Definition Assertions.h:20
uint16_t uint10_t
Definition DataFormats.h:67
std::string asString(const SampaCluster &sc)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
Piece of data for one Sampa channel.
uint32_t sum() const
sum returns the total charge in the cluster
uint16_t nofSamples() const
SampaCluster(uint10_t sampaTime, uint20_t bunchCrossing, uint20_t chargeSum, uint10_t clusterSize)
std::vector< uint16_t > samples
uint16_t nof10BitWords() const
bool isClusterSum() const
isClusterSum returns true if this cluster is not holding raw samples.