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 AliHLTTPCCAClusterData::~AliHLTTPCCAClusterData()
25 if(fAllocated) free(fData);
28 void AliHLTTPCCAClusterData::StartReading( int sliceIndex, int guessForNumberOfClusters )
30 // Start reading of event - initialisation
31 fSliceIndex = sliceIndex;
32 fNumberOfClusters = 0;
33 Allocate(CAMath::Max( 64, guessForNumberOfClusters ));
36 template <class T> void AliHLTTPCCAClusterData::WriteEventVector(const T* const &data, std::ostream &out) const
39 i = fNumberOfClusters;
40 out.write((char*) &i, sizeof(i));
41 out.write((char*) data, i * sizeof(T));
44 template <class T> void AliHLTTPCCAClusterData::ReadEventVector(T* &data, std::istream &in, int MinSize)
47 in.read((char*) &i, sizeof(i));
48 fNumberOfClusters = i;
49 Allocate(CAMath::Max(MinSize, fNumberOfClusters));
50 in.read((char*) data, i * sizeof(T));
53 void AliHLTTPCCAClusterData::WriteEvent(std::ostream &out) const
55 WriteEventVector<Data>(fData, out);
58 void AliHLTTPCCAClusterData::ReadEvent(std::istream &in)
60 ReadEventVector<Data>(fData, in, 64);
63 void AliHLTTPCCAClusterData::Allocate(int number)
68 if (number < fAllocated) return;
69 newnumber = CAMath::Max(number, 2 * fAllocated);
70 fData = (Data*) realloc(fData, newnumber * sizeof(Data));
74 fData = (Data*) malloc(number * sizeof(Data));
77 fAllocated = newnumber;