Line data Source code
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 : AliHLTTPCCAClusterData::~AliHLTTPCCAClusterData()
24 0 : {
25 0 : if(fAllocated) free(fData);
26 0 : }
27 :
28 : void AliHLTTPCCAClusterData::StartReading( int sliceIndex, int guessForNumberOfClusters )
29 : {
30 : // Start reading of event - initialisation
31 0 : fSliceIndex = sliceIndex;
32 0 : fNumberOfClusters = 0;
33 0 : Allocate(CAMath::Max( 64, guessForNumberOfClusters ));
34 0 : }
35 :
36 : template <class T> void AliHLTTPCCAClusterData::WriteEventVector(const T* const &data, std::ostream &out) const
37 : {
38 0 : unsigned i;
39 0 : i = fNumberOfClusters;
40 0 : out.write((char*) &i, sizeof(i));
41 0 : out.write((char*) data, i * sizeof(T));
42 0 : }
43 :
44 : template <class T> void AliHLTTPCCAClusterData::ReadEventVector(T* &data, std::istream &in, int MinSize)
45 : {
46 0 : int i;
47 0 : in.read((char*) &i, sizeof(i));
48 0 : fNumberOfClusters = i;
49 0 : Allocate(CAMath::Max(MinSize, fNumberOfClusters));
50 0 : in.read((char*) data, i * sizeof(T));
51 0 : }
52 :
53 : void AliHLTTPCCAClusterData::WriteEvent(std::ostream &out) const
54 : {
55 0 : WriteEventVector<Data>(fData, out);
56 0 : }
57 :
58 : void AliHLTTPCCAClusterData::ReadEvent(std::istream &in)
59 : {
60 0 : ReadEventVector<Data>(fData, in, 64);
61 0 : }
62 :
63 : void AliHLTTPCCAClusterData::Allocate(int number)
64 : {
65 : int newnumber;
66 0 : if (fAllocated)
67 : {
68 0 : if (number < fAllocated) return;
69 0 : newnumber = CAMath::Max(number, 2 * fAllocated);
70 0 : fData = (Data*) realloc(fData, newnumber * sizeof(Data));
71 0 : }
72 : else
73 : {
74 0 : fData = (Data*) malloc(number * sizeof(Data));
75 : newnumber = number;
76 : }
77 0 : fAllocated = newnumber;
78 0 : }
|