]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAClusterData.h
bug fix: reconstruction crash when the output buffer size exceed
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAClusterData.h
1 // **************************************************************************
2 // * This file is property of and copyright by the ALICE HLT Project        *
3 // * All rights reserved.                                                   *
4 // *                                                                        *
5 // * Primary Authors:                                                       *
6 // *     Copyright 2009       Matthias Kretz <kretz@kde.org>                *
7 // *                                                                        *
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 // **************************************************************************
16
17 #ifndef ALIHLTTPCCACLUSTERDATA_H
18 #define ALIHLTTPCCACLUSTERDATA_H
19
20 #include "AliHLTTPCCADef.h"
21 #include <iostream>
22 #include <vector>
23
24 /**
25  * Cluster data which keeps history about changes
26  *
27  * The algorithm doesn't work on this data. Instead the AliHLTTPCCASliceData is created from this.
28  */
29 class AliHLTTPCCAClusterData
30 {
31   public:
32
33     AliHLTTPCCAClusterData(): fSliceIndex( 0 ), fFirstRow( 0 ), fLastRow( -1 ), fNumberOfClusters(), fRowOffset(), fData() {}
34
35     /**
36      * prepare for the reading of event
37      */
38     void StartReading( int sliceIndex, int guessForNumberOfClusters = 256 );
39
40     /**
41      *  read next cluster
42      */
43     void ReadCluster( int id, int iRow, float x, float y, float z, float amp ) {
44       Data d = { id, iRow, x, y, z, amp};
45       fData.push_back( d );
46     }
47
48     /**
49      * finish the reading of event
50      */
51     void FinishReading();
52
53     /**
54      * Read/Write Events from/to file
55      */
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;
60
61     /**
62      * "remove" one cluster and "add" two new ones, keeping history.
63      */
64     //void Split( int index, /* TODO: need some parameters how to split */ );
65
66     // TODO: some access to history of merges and splits
67
68     /**
69      * The slice index this data belongs to
70      */
71     int SliceIndex() const { return fSliceIndex; }
72
73     /**
74      * The first row index that contains a cluster.
75      */
76     int FirstRow() const { return fFirstRow; }
77
78     /**
79      * The last row index that contains a cluster.
80      */
81     int LastRow() const { return fLastRow; }
82
83     /**
84      * Return the number of clusters in this slice.
85      */
86     int NumberOfClusters() const { return (int) fData.size(); }
87
88     /**
89      * Return the number of clusters in the given row, for this slice.
90      */
91     int NumberOfClusters( unsigned int rowIndex ) const { return rowIndex < fNumberOfClusters.size() ? fNumberOfClusters[rowIndex] : 0; }
92
93     /**
94      * Return the index of the first cluster in the given row.
95      *
96      * Supports calls with rowIndex greater than the available number of rows. In that case it
97      * returns NumberOfClusters.
98      *
99      * To iterate over the clusters in one row do:
100      * \code
101      * AliHLTTPCCAClusterData cd;
102      * const int lastClusterIndex = cd.RowOffset( rowIndex + 1 );
103      * for ( int hitIndex = cd.RowOffset( rowIndex ); hitIndex < lastClusterIndex; ++hitIndex )
104      * \endcode
105      */
106     int RowOffset( unsigned int rowIndex ) const { return rowIndex < fRowOffset.size() ? fRowOffset[rowIndex] : (int) fData.size(); }
107
108     /**
109      * Return the x coordinate of the given cluster.
110      */
111     float X( int index ) const { return fData[index].fX; }
112
113     /**
114      * Return the y coordinate of the given cluster.
115      */
116     float Y( int index ) const { return fData[index].fY; }
117
118     /**
119      * Return the z coordinate of the given cluster.
120      */
121     float Z( int index ) const { return fData[index].fZ; }
122
123     /**
124      * Return the amplitude of the given cluster.
125      */
126     float Amp( int index ) const { return fData[index].fAmp; }
127
128     /**
129      * Return the global ID of the given cluster.
130      */
131     int Id( int index ) const { return fData[index].fId; }
132
133     /**
134      * Return the row number/index of the given cluster.
135      */
136     int RowNumber( int index ) const { return fData[index].fRow; }
137
138     struct Data {
139       int fId;
140       int fRow;
141       float fX;
142       float fY;
143       float fZ;
144       float fAmp;
145     };
146
147     Data *GetClusterData( int index ) { return &( fData[index] ); }
148
149   private:
150     /** TODO
151      * "remove" two clusters and "add" a new one, keeping history.
152      */
153     void Merge( int index1, int index2 );
154
155         static bool CompareClusters( const Data &a, const Data &b ) { return ( a.fRow == b.fRow ? (a.fY < b.fY) : (a.fRow < b.fRow) ); }
156
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
163 };
164
165 typedef AliHLTTPCCAClusterData ClusterData;
166
167 #endif // CLUSTERDATA_H