Project
Loading...
Searching...
No Matches
TPCRawCluster.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//-*- Mode: C++ -*-
13
14#ifndef TPCRAWCLUSTER_H
15#define TPCRAWCLUSTER_H
16//****************************************************************************
17//* This file is free software: you can redistribute it and/or modify *
18//* it under the terms of the GNU General Public License as published by *
19//* the Free Software Foundation, either version 3 of the License, or *
20//* (at your option) any later version. *
21//* *
22//* Primary Authors: Matthias Richter <richterm@scieq.net> *
23//* *
24//* The authors make no claims about the suitability of this software for *
25//* any purpose. It is provided "as is" without express or implied warranty. *
26//****************************************************************************
27
28// @file TPCRawCluster.h
29// @author Matthias Richter
30// @since 2015-09-27
31// @brief ALICE HLT TPC raw cluster structure and tools
32
33#include <iostream>
34#include <fstream> // ifstream
35#include <cstring> // memcpy
36
37namespace o2
38{
39namespace AliceHLT
40{
41
50struct RawCluster {
51
52 int16_t GetPadRow() const { return fPadRow; }
53 float GetPad() const { return fPad; }
54 float GetTime() const { return fTime; }
55 float GetSigmaPad2() const { return fSigmaPad2; }
56 float GetSigmaTime2() const { return fSigmaTime2; }
57 int32_t GetCharge() const { return fCharge; }
58 int32_t GetQMax() const { return fQMax; }
59 bool GetFlagSplitPad() const { return (fFlags & (1 << 0)); }
60 bool GetFlagSplitTime() const { return (fFlags & (1 << 1)); }
61 bool GetFlagSplitAny() const { return (fFlags & 3); }
62 uint16_t GetFlags() const { return (fFlags); }
63
64 int16_t fPadRow;
65 uint16_t fFlags; //Flags: (1 << 0): Split in pad direction
66 // (1 << 1): Split in time direction
67 //During cluster merging, flags are or'd
68 float fPad;
69 float fTime;
72 uint16_t fCharge;
73 uint16_t fQMax;
74};
75
81 uint32_t fVersion; // version number
82 uint32_t fCount; // number of clusters
83 RawCluster fClusters[0]; // array of clusters
84};
85
86std::ostream& operator<<(std::ostream& stream, const RawCluster& cluster)
87{
88 stream << "TPCRawCluster:"
89 << " " << cluster.GetPadRow()
90 << " " << cluster.GetPad()
91 << " " << cluster.GetTime()
92 << " " << cluster.GetSigmaPad2()
93 << " " << cluster.GetSigmaTime2()
94 << " " << cluster.GetCharge()
95 << " " << cluster.GetQMax();
96 return stream;
97}
98
105{
106 public:
107 RawClusterArray() : mBuffer(nullptr), mBufferSize(0), mNClusters(0), mClusters(NULL), mClustersEnd(NULL) {}
108 RawClusterArray(const char* filename) : mBuffer(nullptr), mBufferSize(0), mNClusters(0), mClusters(NULL), mClustersEnd(NULL)
109 {
110 init(filename);
111 }
112 RawClusterArray(unsigned char* buffer, int size) : mBuffer(nullptr), mBufferSize(0), mNClusters(0), mClusters(NULL), mClustersEnd(NULL)
113 {
114 init(buffer, size);
115 }
117
118 typedef uint8_t Buffer_t;
119
120 int init(const char* filename)
121 {
122 std::ifstream input(filename, std::ifstream::binary);
123 clear(0);
124 if (input) {
125 // get length of file:
126 input.seekg(0, input.end);
127 int length = input.tellg();
128 input.seekg(0, input.beg);
129
130 // allocate memory:
131 mBuffer = new Buffer_t[length];
132 mBufferSize = length;
133
134 // read data as a block:
135 input.read(reinterpret_cast<char*>(mBuffer), length);
136 if (!input.good()) {
137 clear(-1);
138 std::cerr << "failed to read " << length << " byte(s) from file " << filename << std::endl;
139 }
140
141 input.close();
142 return init();
143 }
144 std::cerr << "failed to open file " << filename << std::endl;
145 return -1;
146 }
147
148 int init(unsigned char* buffer, int size)
149 {
150 if (!buffer || size <= 0)
151 return -1;
152 clear(0);
153 mBuffer = new Buffer_t[size];
154 mBufferSize = size;
155 memcpy(mBuffer, buffer, size);
156 return init();
157 }
158
159 int GetNClusters() const { return mNClusters; }
160
161 RawCluster* begin() { return mClusters; }
162
163 RawCluster* end() { return mClustersEnd; }
164
166 {
167 if (i + 1 > mNClusters) {
168 // runtime exeption?
169 static RawCluster dummy;
170 return dummy;
171 }
172 return *(mClusters + i);
173 }
174
175 void print() { print(std::cout); }
176
177 template <typename StreamT>
178 StreamT& print(StreamT& stream)
179 {
180 std::cout << "RawClusterArray: " << mNClusters << " cluster(s)" << std::endl;
181 for (RawCluster* cluster = mClusters; cluster != mClustersEnd; cluster++) {
182 std::cout << " " << *cluster << std::endl;
183 }
184 return stream;
185 }
186
187 private:
188 int init()
189 {
190 if (mBuffer == nullptr || mBufferSize == 0)
191 return 0;
192 if (mBufferSize < sizeof(RawClusterData))
193 return -1;
194 RawClusterData& clusterData = *reinterpret_cast<RawClusterData*>(mBuffer);
195
196 if (clusterData.fCount * sizeof(RawCluster) + sizeof(RawClusterData) > mBufferSize) {
197 std::cerr << "Format error, " << clusterData.fCount << " cluster(s) "
198 << "would require "
199 << (clusterData.fCount * sizeof(RawCluster) + sizeof(RawClusterData))
200 << " byte(s), but only " << mBufferSize << " available" << std::endl;
201 return clear(-1);
202 }
203
204 mNClusters = clusterData.fCount;
205 mClusters = clusterData.fClusters;
206 mClustersEnd = mClusters + mNClusters;
207
208 return mNClusters;
209 }
210
211 int clear(int returnValue)
212 {
213 mNClusters = 0;
214 mClusters = NULL;
215 mClustersEnd = NULL;
216 delete[] mBuffer;
217 mBuffer = nullptr;
218 mBufferSize = 0;
219
220 return returnValue;
221 }
222
223 Buffer_t* mBuffer;
224 int mBufferSize;
225 int mNClusters;
226 RawCluster* mClusters;
227 RawCluster* mClustersEnd;
228};
229
230}; // namespace AliceHLT
231}; // namespace o2
232#endif
int32_t i
RawClusterArray(unsigned char *buffer, int size)
RawClusterArray(const char *filename)
StreamT & print(StreamT &stream)
RawCluster & operator[](int i)
int init(unsigned char *buffer, int size)
int init(const char *filename)
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &stream, const RawCluster &cluster)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
float GetSigmaTime2() const
uint16_t GetFlags() const
bool GetFlagSplitTime() const
int32_t GetQMax() const
int16_t GetPadRow() const
int32_t GetCharge() const
vec clear()