1 // **************************************************************************
2 // * This file is property of and copyright by the ALICE HLT Project *
3 // * All rights reserved. *
5 // * Primary Authors: *
6 // * Copyright 2009 Matthias Kretz <kretz@kde.org> *
8 // * Permission to use, copy, modify and distribute this software and its *
9 // * documentation strictly for non-commercial purposes is hereby granted *
10 // * without fee, provided that the above copyright notice appears in all *
11 // * copies and that both the copyright notice and this permission notice *
12 // * appear in the supporting documentation. The authors make no claims *
13 // * about the suitability of this software for any purpose. It is *
14 // * provided "as is" without express or implied warranty. *
15 // **************************************************************************
17 #ifndef ALIHLTTPCCACLUSTERDATA_H
18 #define ALIHLTTPCCACLUSTERDATA_H
20 #include "AliHLTTPCCADef.h"
25 * Cluster data which keeps history about changes
27 * The algorithm doesn't work on this data. Instead the AliHLTTPCCASliceData is created from this.
29 class AliHLTTPCCAClusterData
33 AliHLTTPCCAClusterData(): fSliceIndex( 0 ), fFirstRow( 0 ), fLastRow( -1 ), fNumberOfClusters(), fRowOffset(), fData() {}
36 * prepare for the reading of event
38 void StartReading( int sliceIndex, int guessForNumberOfClusters = 256 );
43 void ReadCluster( int id, int iRow, float x, float y, float z, float amp ) {
44 Data d = { id, iRow, x, y, z, amp};
49 * finish the reading of event
54 * Read/Write Events from/to file
56 void ReadEvent(std::istream &in);
57 void WriteEvent(std::ostream &out) const;
58 template <class T> void ReadEventVector(std::vector<T> &data, std::istream &in, int MinSize = 0);
59 template <class T> void WriteEventVector(const std::vector<T> &data, std::ostream &out) const;
62 * "remove" one cluster and "add" two new ones, keeping history.
64 //void Split( int index, /* TODO: need some parameters how to split */ );
66 // TODO: some access to history of merges and splits
69 * The slice index this data belongs to
71 int SliceIndex() const { return fSliceIndex; }
74 * The first row index that contains a cluster.
76 int FirstRow() const { return fFirstRow; }
79 * The last row index that contains a cluster.
81 int LastRow() const { return fLastRow; }
84 * Return the number of clusters in this slice.
86 int NumberOfClusters() const { return (int) fData.size(); }
89 * Return the number of clusters in the given row, for this slice.
91 int NumberOfClusters( unsigned int rowIndex ) const { return rowIndex < fNumberOfClusters.size() ? fNumberOfClusters[rowIndex] : 0; }
94 * Return the index of the first cluster in the given row.
96 * Supports calls with rowIndex greater than the available number of rows. In that case it
97 * returns NumberOfClusters.
99 * To iterate over the clusters in one row do:
101 * AliHLTTPCCAClusterData cd;
102 * const int lastClusterIndex = cd.RowOffset( rowIndex + 1 );
103 * for ( int hitIndex = cd.RowOffset( rowIndex ); hitIndex < lastClusterIndex; ++hitIndex )
106 int RowOffset( unsigned int rowIndex ) const { return rowIndex < fRowOffset.size() ? fRowOffset[rowIndex] : (int) fData.size(); }
109 * Return the x coordinate of the given cluster.
111 float X( int index ) const { return fData[index].fX; }
114 * Return the y coordinate of the given cluster.
116 float Y( int index ) const { return fData[index].fY; }
119 * Return the z coordinate of the given cluster.
121 float Z( int index ) const { return fData[index].fZ; }
124 * Return the amplitude of the given cluster.
126 float Amp( int index ) const { return fData[index].fAmp; }
129 * Return the global ID of the given cluster.
131 int Id( int index ) const { return fData[index].fId; }
134 * Return the row number/index of the given cluster.
136 int RowNumber( int index ) const { return fData[index].fRow; }
147 Data *GetClusterData( int index ) { return &( fData[index] ); }
151 * "remove" two clusters and "add" a new one, keeping history.
153 void Merge( int index1, int index2 );
155 static bool CompareClusters( const Data &a, const Data &b ) { return ( a.fRow == b.fRow ? (a.fY < b.fY) : (a.fRow < b.fRow) ); }
157 int fSliceIndex; // the slice index this data belongs to
158 int fFirstRow; // see FirstRow()
159 int fLastRow; // see LastRow()
160 std::vector<int> fNumberOfClusters; // list of NumberOfClusters per row for NumberOfClusters(int)
161 std::vector<int> fRowOffset; // see RowOffset()
162 std::vector<Data> fData; // list of data of clusters
165 typedef AliHLTTPCCAClusterData ClusterData;
167 #endif // CLUSTERDATA_H