]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
Fixing memory leak (Christian)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
a38a7850 8 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
71d7c760 9 * for The ALICE Off-line Project. *
10 * *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// a TPC cluster finder processing component for the HLT //
a38a7850 23// useable for packed data or unpacked data //
71d7c760 24// //
25///////////////////////////////////////////////////////////////////////////////
26
a38a7850 27
71d7c760 28#if __GNUC__== 3
29using namespace std;
30#endif
31
32#include "AliHLTTPCClusterFinderComponent.h"
a38a7850 33#include "AliHLTTPCDigitReaderPacked.h"
34#include "AliHLTTPCDigitReaderUnpacked.h"
35#include "AliHLTTPCClusterFinder.h"
a6c02c85 36#include "AliHLTTPCSpacePointData.h"
71d7c760 37#include "AliHLTTPCRawDataFormat.h"
38#include "AliHLTTPCClusterDataFormat.h"
a6c02c85 39#include "AliHLTTPCTransform.h"
71d7c760 40#include <stdlib.h>
41#include <errno.h>
42
43// this is a global object used for automatic component registration, do not use this
a38a7850 44AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
45AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
71d7c760 46
47ClassImp(AliHLTTPCClusterFinderComponent)
48
a38a7850 49AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
71d7c760 50 {
a38a7850 51 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
52 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
53 fPackedSwitch = packed;
54
71d7c760 55 fClusterFinder = NULL;
a38a7850 56 fReaderPacked = NULL;
57 fReaderUnpacked = NULL;
71d7c760 58 fClusterDeconv = true;
59 fXYClusterError = -1;
60 fZClusterError = -1;
61 }
62
63AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
64 {
65 }
66
67// Public functions to implement AliHLTComponent's interface.
68// These functions are required for the registration process
69
70const char* AliHLTTPCClusterFinderComponent::GetComponentID()
71 {
a38a7850 72 if (fPackedSwitch) return "TPCClusterFinderPacked";
73 else return "TPCClusterFinderUnpacked";
71d7c760 74 }
75
76void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
77 {
a38a7850 78 list.clear();
79 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
80 else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
81
71d7c760 82 }
83
84AliHLTComponent_DataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
85 {
86 return AliHLTTPCDefinitions::gkClustersDataType;
87 }
88
89void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
90 {
a38a7850 91 // XXX TODO: Find more realistic values.
71d7c760 92 constBase = 0;
a38a7850 93 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
94 else inputMultiplier = 0.4;
71d7c760 95 }
96
97AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
98 {
a38a7850 99 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
71d7c760 100 }
101
102int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
103 {
104 if ( fClusterFinder )
105 return EINPROGRESS;
a38a7850 106
107 fClusterFinder = new AliHLTTPCClusterFinder();
108
109 if (fPackedSwitch) {
110 fReaderPacked = new AliHLTTPCDigitReaderPacked();
111 fClusterFinder->SetReader(fReaderPacked);
112 }
113 else {
114 fReaderUnpacked = new AliHLTTPCDigitReaderUnpacked();
115 fClusterFinder->SetReader(fReaderUnpacked);
116 }
117
118 // Variables to setup the Clusterfinder
71d7c760 119 fClusterDeconv = true;
120 fXYClusterError = -1;
121 fZClusterError = -1;
a38a7850 122
71d7c760 123 int i = 0;
124 while ( i < argc )
125 {
a38a7850 126 if ( !strcmp( argv[i], "pp-run" ) ){
71d7c760 127 fClusterDeconv = false;
128 i++;
129 continue;
a38a7850 130 }
131
71d7c760 132 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
133 return EINVAL;
134 }
a38a7850 135
136
137 fClusterFinder->SetDeconv( fClusterDeconv );
138 fClusterFinder->SetXYError( fXYClusterError );
139 fClusterFinder->SetZError( fZClusterError );
140 if ( (fXYClusterError>0) && (fZClusterError>0) )
141 fClusterFinder->SetCalcErr( false );
142
71d7c760 143 return 0;
144 }
145
146int AliHLTTPCClusterFinderComponent::DoDeinit()
147 {
a38a7850 148
71d7c760 149 if ( fClusterFinder )
150 delete fClusterFinder;
151 fClusterFinder = NULL;
a38a7850 152
153 if ( fReaderUnpacked )
154 delete fReaderUnpacked;
155 fReaderUnpacked = NULL;
156
157 if ( fReaderPacked )
158 delete fReaderPacked;
159 fReaderPacked = NULL;
160
71d7c760 161 return 0;
162 }
163
a38a7850 164int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponent_EventData& evtData,
165 const AliHLTComponent_BlockData* blocks,
71d7c760 166 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
a38a7850 167 AliHLTUInt32_t& size,
168 vector<AliHLTComponent_BlockData>& outputBlocks )
71d7c760 169 {
a38a7850 170 // == init iter (pointer to datablock)
71d7c760 171 const AliHLTComponent_BlockData* iter = NULL;
172 unsigned long ndx;
a38a7850 173
174 // == OUTdatatype pointer
71d7c760 175 AliHLTTPCClusterData* outPtr;
a38a7850 176
71d7c760 177 AliHLTUInt8_t* outBPtr;
178 UInt_t offset, mysize, nSize, tSize = 0;
a38a7850 179
71d7c760 180 outBPtr = outputPtr;
181 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 182
71d7c760 183 Int_t slice, patch, row[2];
184 unsigned long maxPoints, realPoints = 0;
a38a7850 185
71d7c760 186 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
187 {
188 iter = blocks+ndx;
189 mysize = 0;
190 offset = tSize;
a38a7850 191
192
193 if (fPackedSwitch) {
194 char tmp1[14], tmp2[14];
195 DataType2Text( iter->fDataType, tmp1 );
196 DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
197 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
198 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
199 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
200
201 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
202
203 }
204 else {
205 char tmp1[14], tmp2[14];
206 DataType2Text( iter->fDataType, tmp1 );
207 DataType2Text( AliHLTTPCDefinitions::gkUnpackedRawDataType, tmp2 );
208 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
209 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
210 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
211
212 if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
213
214 }
215
71d7c760 216 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
217 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
a6c02c85 218 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
219 row[1] = AliHLTTPCTransform::GetLastRow( patch );
71d7c760 220
221 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
222 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
223 realPoints, slice, patch, row[0], row[1] );
224
225 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 226
a6c02c85 227 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
71d7c760 228
229 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
71d7c760 230 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
a38a7850 231 fClusterFinder->Read(iter->fPtr, iter->fSize );
71d7c760 232 fClusterFinder->ProcessDigits();
233 realPoints = fClusterFinder->GetNumberOfClusters();
234
235 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
236 "Number of spacepoints found: %lu.", realPoints );
237
238 outPtr->fSpacePointCnt = realPoints;
a6c02c85 239 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
71d7c760 240 mysize += nSize+sizeof(AliHLTTPCClusterData);
241
242 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
243 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
244 realPoints, slice, patch, row[0], row[1] );
245
246
247 AliHLTComponent_BlockData bd;
248 FillBlockData( bd );
249 bd.fOffset = offset;
250 bd.fSize = mysize;
251 bd.fSpecification = iter->fSpecification;
252 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
253 outputBlocks.push_back( bd );
254
255 tSize += mysize;
256 outBPtr += mysize;
257 outPtr = (AliHLTTPCClusterData*)outBPtr;
258
259 if ( tSize > size )
260 {
261 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
262 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
263 tSize, size );
264 return EMSGSIZE;
265 }
266 }
267
268 size = tSize;
269 return 0;
270 }
271
a38a7850 272