]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
Obsolete tracker output removed
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWClusterTransformComponent.cxx
CommitLineData
a9d14303 1// $Id$
6af4f584 2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
18
19/** @file AliHLTTPCHWClusterTransformComponent.cxx
20 @author Kalliopi Kanaki
21 @date
22 @brief
23*/
24
25#if __GNUC__>= 3
26using namespace std;
27#endif
28#include "AliHLTTPCHWClusterTransformComponent.h"
29#include "AliHLTTPCDefinitions.h"
30#include "AliHLTTPCTransform.h"
31#include "AliHLTTPCSpacePointData.h"
32#include "AliHLTTPCClusterDataFormat.h"
33
a9d14303 34#include "AliTPCcalibDB.h"
35#include "AliTPCTransform.h"
641530bb 36#include "AliTPCCalPad.h"
a9d14303 37
491d6af5 38#include "AliCDBManager.h"
39#include "AliCDBEntry.h"
40
2b727eff 41#include "TMath.h"
7361746a 42#include "TObjString.h"
6af4f584 43#include <cstdlib>
44#include <cerrno>
45#include <sys/time.h>
46
47ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
48
84e36c27 49const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
50
6af4f584 51AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
a9d14303 52:
491d6af5 53fOfflineTransform(NULL),
84e36c27 54fDataId(kFALSE),
58df4cfa 55fChargeThreshold(10),
84e36c27 56fOfflineTPCRecoParam()
6af4f584 57{
58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
a9d14303 62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
6af4f584 63}
64
65AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
66// see header file for class documentation
67}
68
69const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
70// see header file for class documentation
71
72 return "TPCHWClusterTransform";
73}
74
75void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
76 // see header file for class documentation
77
78 list.clear();
79 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
80}
81
82AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
83 // see header file for class documentation
84
85 return AliHLTTPCDefinitions::fgkClustersDataType;
86}
87
88int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
89 // see header file for class documentation
90
91 tgtList.clear();
92 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
93 return tgtList.size();
94}
95
96void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
97 // see header file for class documentation
6af4f584 98 constBase = 0;
641530bb 99 inputMultiplier = 3.0;
6af4f584 100}
101
102AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
103 // see header file for class documentation
104
105 return new AliHLTTPCHWClusterTransformComponent();
106}
107
491d6af5 108int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
6af4f584 109// see header file for class documentation
110
b4c689c4 111 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
112 if(!pCalib ||
113 !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
491d6af5 114 HLTError("Cannot retrieve offline transform from AliTPCcalibDB (%p)", pCalib);
b4c689c4 115 return -ENOENT;
116 }
84e36c27 117 // set the flags in the reco param
118 fOfflineTPCRecoParam.SetUseExBCorrection(1);
119 fOfflineTPCRecoParam.SetUseTOFCorrection(1);
120 fOfflineTransform->SetCurrentRecoParam(&fOfflineTPCRecoParam);
121
122 pCalib->SetExBField(GetBz());
491d6af5 123
124 int iResult=0;
84e36c27 125 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
126
127 if (iResult>=0 && argc>0)
128 iResult=ConfigureFromArgumentString(argc, argv);
129
130 return iResult;
6af4f584 131} // end DoInit()
132
133int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
bd1ecd64 134 // see header file for class documentation
6af4f584 135 return 0;
136}
137
138int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
491d6af5 139 const AliHLTComponentBlockData* blocks,
140 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
141 AliHLTUInt32_t& size,
142 vector<AliHLTComponentBlockData>& outputBlocks ){
6af4f584 143 // see header file for class documentation
bd1ecd64 144
6af4f584 145 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
146 size = 0;
147 return 0;
148 }
bd1ecd64 149
6af4f584 150 const AliHLTComponentBlockData *iter = NULL;
151 unsigned long ndx;
152
153 AliHLTTPCClusterData* outPtr;
154
155 AliHLTUInt8_t* outBPtr;
156 UInt_t offset, mysize, nSize, tSize = 0;
157
158 outBPtr = outputPtr;
159 outPtr = (AliHLTTPCClusterData*)outBPtr;
160
161 AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
162
163 unsigned long maxPoints = 0;
bd1ecd64 164
6af4f584 165 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
166
167 iter = blocks+ndx;
168 mysize = 0;
169 offset = tSize;
170
171 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
491d6af5 172 evtData.fEventID, evtData.fEventID,
173 DataType2Text( iter->fDataType).c_str(),
174 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
6af4f584 175
176 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
177
178 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
179 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
180 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
181 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
491d6af5 182
183 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
6af4f584 184
185 outPtr = (AliHLTTPCClusterData*)outBPtr;
186 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
187
188 AliHLTUInt32_t *buffer;
189 buffer = (AliHLTUInt32_t*)iter->fPtr;
190
191 /*
192 //cluster fabrication
193 buffer = new AliHLTUInt32_t[14];
194 //header
195 buffer[0]=0xffffffff;
196 buffer[1]=0xffffffff;
197 buffer[2]=0xffffffff;
198 buffer[3]=0xffffffff;
199 buffer[4]=0xffffffff;
200 buffer[5]=0xffffffff;
201 buffer[6]=0xffffffff;
202 buffer[7]=0xffffffff;
203 //cluster 1
204 buffer[8]=0xC60002EF;
205 buffer[9]=0x0;
206 buffer[10]=0x0;
207 buffer[11]=0x0;
208 buffer[12]=0x0;
209 //RCU trailer
210 buffer[13]=0x80000000;
211 */
212
213 Int_t sector=-99, thisrow=-99;
214
215 // PrintDebug(buffer, 14);
216
217 // skip the first 8 32-bit CDH words
218 buffer += 8;
219
220 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
221
222 unsigned long nAddedClusters = 0;
223
224 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
225 // for(UInt_t nWords=0; nWords<5; nWords+=5){
bd1ecd64 226
6af4f584 227 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
228 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
229
84e36c27 230
6af4f584 231 if(bit3130 == 0x3){ //beginning of a cluster
232
233 //PrintDebug(&buffer[nWords], 5);
234
235 if(nAddedClusters>=maxPoints){
236 HLTWarning("No more space to add clusters, exiting!");
237 break;
238 }
bd1ecd64 239
6af4f584 240
241 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
242
243 //get the first word
244 AliHLTUInt32_t rowCharge = buffer[nWords];
245 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
246 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
247
248 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
641530bb 249 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
250
251 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
252 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
bd1ecd64 253 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
254 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
2b727eff 255
116fb816 256
58df4cfa 257 if(cluster.fCharge<fChargeThreshold) continue;
116fb816 258
2b727eff 259 // correct expressions for the error calculation
84e36c27 260 // Kenneth: 12.11.2009 I'm not sure if this is a correct calculation. Leave it out for now since it is anyway not used later since it caused segfaults.
261 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
262 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
2b727eff 263
641530bb 264 Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
491d6af5 265
266 HLTDebug("padrow: %d, charge: %f, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (Float_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);
116fb816 267
268 //fOfflineTransform=NULL;
269
641530bb 270 if(fOfflineTransform == NULL){
a9d14303 271 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
272 AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);
641530bb 273 AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, tmpPad, tmpTime);
a9d14303 274 if(minSlice>17) xyz[1]=(-1)*xyz[1];
275 cluster.fX = xyz[0];
276 cluster.fY = xyz[1];
277 cluster.fZ = xyz[2];
116fb816 278 } else {
279
280
281
282 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
283
bd1ecd64 284 AliHLTTPCTransform::Slice2Sector(minSlice, (UInt_t)cluster.fPadRow, sector, thisrow);
116fb816 285
286
287 Double_t x[3] = {thisrow,tmpPad+.5,tmpTime};
641530bb 288 Int_t iSector[1]= {sector};
289 fOfflineTransform->Transform(x,iSector,0,1);
290 cluster.fX = x[0];
291 cluster.fY = x[1];
bd1ecd64 292 cluster.fZ = x[2];
293 }
84e36c27 294
491d6af5 295 HLTDebug("cluster X: %f, Y: %f, Z: %f \n", cluster.fX, cluster.fY, cluster.fZ);
6af4f584 296 spacePoints[nAddedClusters] = cluster;
297
298 nAddedClusters++;
299 } // end of clusters starting with 11=0x3
300 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
301 break;
302 }
303 } // end of loop over clusters
304
305 HLTDebug("Number of found clusters: %d", nAddedClusters);
306
307 outPtr->fSpacePointCnt = nAddedClusters;
308 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
309 mysize += nSize+sizeof(AliHLTTPCClusterData);
310
311 AliHLTComponentBlockData bd;
312 FillBlockData( bd );
313 bd.fOffset = offset;
314 bd.fSize = mysize;
315 bd.fSpecification = iter->fSpecification;
491d6af5 316
317 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
318 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
319
320 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
321
6af4f584 322 outputBlocks.push_back( bd );
323
324 tSize += mysize;
325 outBPtr += mysize;
326 outPtr = (AliHLTTPCClusterData*)outBPtr;
327
328 } // end of loop over data blocks
329 size = tSize;
330 return 0;
331} // end DoEvent()
84e36c27 332
333int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
334
335 // see header file for class documentation
336
337 if (argc<=0) return 0;
338 int i=0;
339 TString argument=argv[i];
340
341 if (argument.CompareTo("-solenoidBz")==0){
342 if (++i>=argc) return -EPROTO;
343 argument=argv[i];
344 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
345 if(!calib){
bd1ecd64 346 HLTError("CalibDB not available");
84e36c27 347 }
348 Float_t magneticField = argument.Atof();
349 calib->SetExBField(magneticField);
350 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
351 return 2;
352 }
353
354 if (argument.CompareTo("-change-dataId")==0){
355 HLTDebug("Change data ID received.");
356 fDataId = kTRUE;
357 return 1;
358 }
58df4cfa 359
360 if (argument.CompareTo("-charge-threshold")==0) {
361 if (++i>=argc) return -EPROTO;
362 argument=argv[i];
363 fChargeThreshold=argument.Atof();
364 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
365 return 2;
366 }
84e36c27 367
368 // unknown argument
369 return -EINVAL;
370}
371
84e36c27 372int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
491d6af5 373 // see header file for class documentation
84e36c27 374 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
491d6af5 375}
6af4f584 376
377void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
378// see header file for class documentation
379
380 HLTInfo("The size is: %d", size);
381 for(Int_t n32bit=0; n32bit<size; n32bit++){
382
383 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
384 // cout << "word ptr initialized"<<endl;
385 for(Int_t w=3;w>=0;w--){
386 // cout <<"accessing word"<<endl;
387 AliHLTUInt8_t word = wordPtr[w];
388 // cout<< "word was accessed"<<endl;
389 for(int n=7; n>=0; n--){
390 //print the byte values
391 if((((word>>n)<<7)&0x80) != 0){
392 printf("1");
393 }
394 else{
395 printf("0");
396 }
397 }
398 printf(" ");
399 }
400 printf("\n");
401 }
402} // end of PrintDebug