]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAClusterData.cxx
adding newline at end of file
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAClusterData.cxx
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 #include "AliHLTTPCCAClusterData.h"
18 #include "AliHLTTPCCAMath.h"
19 #include <algorithm>
20 #include "AliHLTArray.h"
21 #include "AliHLTTPCCAGPUConfig.h"
22
23 void AliHLTTPCCAClusterData::StartReading( int sliceIndex, int guessForNumberOfClusters )
24 {
25   // Start reading of event - initialisation
26
27   fSliceIndex = sliceIndex;
28   fFirstRow = 0;
29   fLastRow = 0;
30   fData.clear();
31   fNumberOfClusters.reserve( HLTCA_ROW_COUNT + 1 );
32   fRowOffset.reserve( HLTCA_ROW_COUNT + 1 );
33   fData.reserve( CAMath::Max( 64, guessForNumberOfClusters ) );
34 }
35
36
37 void AliHLTTPCCAClusterData::FinishReading()
38 {
39   // finish event reading - data sorting, etc.
40
41   std::sort( fData.begin(), fData.end(), CompareClusters );
42   if ( fData.size() ) fFirstRow = fData[0].fRow;
43
44   fNumberOfClusters.clear();
45   fRowOffset.clear();
46
47   int row = fFirstRow;
48   for ( int i = 0; i < row; ++i ) {
49     fNumberOfClusters.push_back( 0 );
50     fRowOffset.push_back( 0 );
51   }
52   fRowOffset.push_back( 0 );
53   for ( unsigned int ic = 0; ic < fData.size(); ++ic ) {
54     Data &cluster = fData[ic];
55     while ( row < cluster.fRow ) {
56       fNumberOfClusters.push_back( ic - fRowOffset.back() );
57       fRowOffset.push_back( ic );
58       ++row;
59     }
60   }
61   fNumberOfClusters.push_back( fData.size() - fRowOffset.back() );
62   fLastRow = row; // the last seen row is the last row in this slice
63 }
64
65 template <class T> void AliHLTTPCCAClusterData::WriteEventVector(const std::vector<T> &data, std::ostream &out) const
66 {
67         AliHLTResizableArray<T> tmpData(data.size());
68         unsigned i;
69         for (i = 0;i < data.size();i++)
70         {
71                 tmpData[i] = data[i];
72         }
73         i = data.size();
74         out.write((char*) &i, sizeof(i));
75         out.write((char*) &tmpData[0], i * sizeof(T));
76 }
77
78 template <class T> void AliHLTTPCCAClusterData::ReadEventVector(std::vector<T> &data, std::istream &in, int MinSize)
79 {
80         int i;
81         in.read((char*) &i, sizeof(i));
82         data.reserve(AliHLTTPCCAMath::Max(MinSize, i));
83         data.resize(i);
84         AliHLTResizableArray<T> tmpData(i);
85         in.read((char*) &tmpData[0], i * sizeof(T));
86         for (int j = 0;j < i;j++)
87         {
88 #ifdef HLTCA_STANDALONE
89                 if (tmpData[j].fRow < 0 || tmpData[j].fRow >= HLTCA_ROW_COUNT)
90                 {
91                         printf("Invalid Row Read %d at Cluster %d\n", tmpData[j].fRow, j);
92                         exit(1);
93                 }
94 #endif
95                 data[j] = tmpData[j];
96         }
97 }
98
99 void AliHLTTPCCAClusterData::WriteEvent(std::ostream &out) const
100 {
101         WriteEventVector<Data>(fData, out);
102 }
103
104 void AliHLTTPCCAClusterData::ReadEvent(std::istream &in)
105 {
106     fData.clear();
107         ReadEventVector<Data>(fData, in, 64);
108 }
109