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