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 #include "AliHLTTPCCAClusterData.h"
18 #include "AliHLTTPCCAMath.h"
20 #include "AliHLTArray.h"
21 #include "AliHLTTPCCAGPUConfig.h"
23 void AliHLTTPCCAClusterData::StartReading( int sliceIndex, int guessForNumberOfClusters )
25 // Start reading of event - initialisation
27 fSliceIndex = sliceIndex;
31 fNumberOfClusters.reserve( HLTCA_ROW_COUNT + 1 );
32 fRowOffset.reserve( HLTCA_ROW_COUNT + 1 );
33 fData.reserve( CAMath::Max( 64, guessForNumberOfClusters ) );
37 void AliHLTTPCCAClusterData::FinishReading()
39 // finish event reading - data sorting, etc.
41 std::sort( fData.begin(), fData.end(), CompareClusters );
42 if ( fData.size() ) fFirstRow = fData[0].fRow;
44 fNumberOfClusters.clear();
48 for ( int i = 0; i < row; ++i ) {
49 fNumberOfClusters.push_back( 0 );
50 fRowOffset.push_back( 0 );
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 );
61 fNumberOfClusters.push_back( fData.size() - fRowOffset.back() );
62 fLastRow = row; // the last seen row is the last row in this slice
65 template <class T> void AliHLTTPCCAClusterData::WriteEventVector(const std::vector<T> &data, std::ostream &out) const
67 AliHLTResizableArray<T> tmpData(data.size());
69 for (i = 0;i < data.size();i++)
74 out.write((char*) &i, sizeof(i));
75 out.write((char*) &tmpData[0], i * sizeof(T));
78 template <class T> void AliHLTTPCCAClusterData::ReadEventVector(std::vector<T> &data, std::istream &in, int MinSize)
81 in.read((char*) &i, sizeof(i));
82 data.reserve(AliHLTTPCCAMath::Max(MinSize, i));
84 AliHLTResizableArray<T> tmpData(i);
85 in.read((char*) &tmpData[0], i * sizeof(T));
86 for (int j = 0;j < i;j++)
88 #ifdef HLTCA_STANDALONE
89 if (tmpData[j].fRow < 0 || tmpData[j].fRow >= HLTCA_ROW_COUNT)
91 printf("Invalid Row Read %d at Cluster %d\n", tmpData[j].fRow, j);
99 void AliHLTTPCCAClusterData::WriteEvent(std::ostream &out) const
101 WriteEventVector<Data>(fData, out);
104 void AliHLTTPCCAClusterData::ReadEvent(std::istream &in)
107 ReadEventVector<Data>(fData, in, 64);