Project
Loading...
Searching...
No Matches
SampaCluster.h
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
12#ifndef O2_MCH_RAW_SAMPA_CLUSTER_H
13#define O2_MCH_RAW_SAMPA_CLUSTER_H
14
15#include <cstdlib>
16#include <vector>
17#include <iostream>
18#include <fmt/format.h>
20
21namespace o2
22{
23namespace mch
24{
25namespace raw
26{
27
39
41
50
57 SampaCluster(uint10_t sampaTime, uint20_t bunchCrossing, const std::vector<uint10_t>& samples);
58
62 uint16_t nofSamples() const;
63
65 bool isClusterSum() const;
66
69 uint16_t nof10BitWords() const;
70
72 uint32_t sum() const;
73
74 uint10_t sampaTime; //< 10 bits for a local time stamp
75 uint20_t bunchCrossing; //< 20 bits for bunch crossing counter
76 uint20_t chargeSum; //< 20 bits for a cluster sum
77 uint10_t clusterSize; //< 10 bits for cluster size
78 std::vector<uint16_t> samples; //< 10 bits for each sample
79};
80
81// ensure all clusters are either in sample mode or in
82// chargesum mode, no mixing allowed
83// and that all clusters share a single bunch crossing counter value
84template <typename CHARGESUM>
85void assertNotMixingClusters(const std::vector<SampaCluster>& data)
86{
87 CHARGESUM a;
88 auto refValue = a();
89 uint32_t bunchCrossingCounter{0};
90 for (auto i = 0; i < data.size(); i++) {
91 if (data[i].isClusterSum() != refValue) {
92 throw std::invalid_argument(fmt::format("all cluster of this encoder should be of the same type ({}) but {}-th does not match ", (refValue ? "clusterSum" : "samples"), i));
93 }
94 auto bc = data[i].bunchCrossing;
95 if (i == 0) {
96 bunchCrossingCounter = bc;
97 }
98 if (bc != bunchCrossingCounter) {
99 throw std::invalid_argument(fmt::format("all sampa clusters should have the same bunch crossing number : first is {} and got {}\n", bunchCrossingCounter, bc));
100 }
101 }
102}
103
104std::ostream& operator<<(std::ostream& os, const SampaCluster& sc);
105
106std::string asString(const SampaCluster& sc);
107
108} // namespace raw
109} // namespace mch
110} // namespace o2
111#endif
uint64_t bc
Definition RawEventData.h:5
int32_t i
GLboolean * data
Definition glcorearb.h:298
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
void assertNotMixingClusters(const std::vector< SampaCluster > &data)
uint16_t uint10_t
Definition DataFormats.h:67
uint32_t uint20_t
Definition DataFormats.h:68
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
std::vector< uint16_t > samples
uint16_t nof10BitWords() const
bool isClusterSum() const
isClusterSum returns true if this cluster is not holding raw samples.