]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
adding ROOTLIBS library dependencies to HLTbase
[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
491d6af5 34#include "AliCDBManager.h"
35#include "AliCDBEntry.h"
dccee396 36#include "AliTPCcalibDB.h"
491d6af5 37
2b727eff 38#include "TMath.h"
7361746a 39#include "TObjString.h"
6af4f584 40#include <cstdlib>
41#include <cerrno>
42#include <sys/time.h>
43
44ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
45
84e36c27 46const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
47
6af4f584 48AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
a9d14303 49:
84e36c27 50fDataId(kFALSE),
58df4cfa 51fChargeThreshold(10),
dccee396 52fTransform(),
a5dc9013 53fBenchmark("HWClusterTransform")
6af4f584 54{
55 // see header file for class documentation
56 // or
57 // refer to README to build package
58 // or
a9d14303 59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
a5dc9013 60
61 fBenchmark.Reset();
62 fBenchmark.SetTimer(0,"total");
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
dccee396 110
aa0d6ff8 111 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
112 if(!calib){
113 HLTError("AliTPCcalibDB does not exist");
114 return -ENOENT;
115 }
116 calib->SetRun(GetRunNo());
117 calib->UpdateRunInformations(GetRunNo());
118
dccee396 119 int err = fTransform.Init( GetBz(), GetTimeStamp() );
6af4f584 120
dccee396 121 if( err!=0 ){
122 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
b4c689c4 123 return -ENOENT;
124 }
491d6af5 125
126 int iResult=0;
84e36c27 127 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
128
129 if (iResult>=0 && argc>0)
130 iResult=ConfigureFromArgumentString(argc, argv);
131
132 return iResult;
6af4f584 133} // end DoInit()
134
135int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
bd1ecd64 136 // see header file for class documentation
6af4f584 137 return 0;
138}
139
140int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
491d6af5 141 const AliHLTComponentBlockData* blocks,
142 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
143 AliHLTUInt32_t& size,
144 vector<AliHLTComponentBlockData>& outputBlocks ){
6af4f584 145 // see header file for class documentation
bd1ecd64 146
6af4f584 147 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
148 size = 0;
149 return 0;
150 }
a5dc9013 151
152 fBenchmark.StartNewEvent();
153 fBenchmark.Start(0);
154
dccee396 155 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
156
6af4f584 157 const AliHLTComponentBlockData *iter = NULL;
61c1f30c 158 unsigned long ndx;
6af4f584 159
160 AliHLTUInt8_t* outBPtr;
161 UInt_t offset, mysize, nSize, tSize = 0;
162
163 outBPtr = outputPtr;
61c1f30c 164
6af4f584 165 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
166
167 iter = blocks+ndx;
168 mysize = 0;
169 offset = tSize;
a5dc9013 170
171 fBenchmark.AddInput(iter->fSize);
172
6af4f584 173 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
491d6af5 174 evtData.fEventID, evtData.fEventID,
175 DataType2Text( iter->fDataType).c_str(),
176 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
6af4f584 177
178 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
179
180 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
181 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
182 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
183 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
a5dc9013 184
185 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
186
491d6af5 187 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
6af4f584 188
61c1f30c 189 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outBPtr;
190
191 unsigned long maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
6af4f584 192
193 AliHLTUInt32_t *buffer;
194 buffer = (AliHLTUInt32_t*)iter->fPtr;
195
196 /*
197 //cluster fabrication
198 buffer = new AliHLTUInt32_t[14];
199 //header
200 buffer[0]=0xffffffff;
201 buffer[1]=0xffffffff;
202 buffer[2]=0xffffffff;
203 buffer[3]=0xffffffff;
204 buffer[4]=0xffffffff;
205 buffer[5]=0xffffffff;
206 buffer[6]=0xffffffff;
207 buffer[7]=0xffffffff;
208 //cluster 1
209 buffer[8]=0xC60002EF;
210 buffer[9]=0x0;
211 buffer[10]=0x0;
212 buffer[11]=0x0;
213 buffer[12]=0x0;
214 //RCU trailer
215 buffer[13]=0x80000000;
216 */
217
6af4f584 218 // PrintDebug(buffer, 14);
219
220 // skip the first 8 32-bit CDH words
221 buffer += 8;
222
223 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
224
225 unsigned long nAddedClusters = 0;
226
227 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
228 // for(UInt_t nWords=0; nWords<5; nWords+=5){
bd1ecd64 229
6af4f584 230 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
231 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
232
84e36c27 233
6af4f584 234 if(bit3130 == 0x3){ //beginning of a cluster
235
236 //PrintDebug(&buffer[nWords], 5);
237
238 if(nAddedClusters>=maxPoints){
239 HLTWarning("No more space to add clusters, exiting!");
240 break;
241 }
bd1ecd64 242
6af4f584 243
244 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
245
246 //get the first word
247 AliHLTUInt32_t rowCharge = buffer[nWords];
248 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
249 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
250
251 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
641530bb 252 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
253
254 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
255 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
bd1ecd64 256 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
257 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
2b727eff 258
116fb816 259
58df4cfa 260 if(cluster.fCharge<fChargeThreshold) continue;
116fb816 261
2b727eff 262 // correct expressions for the error calculation
84e36c27 263 // 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.
264 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
265 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
491d6af5 266
caa1158d 267 HLTDebug("padrow: %d, charge: %d, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (UInt_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);
dccee396 268
269 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
116fb816 270
dccee396 271 Float_t xyz[3];
272 fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
273 cluster.fX = xyz[0];
274 cluster.fY = xyz[1];
275 cluster.fZ = xyz[2];
84e36c27 276
b3fe7b2c 277 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
a371a266 278 cluster.SetID( minSlice, minPartition, nAddedClusters );
b3fe7b2c 279
280 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
61c1f30c 281 outPtr->fSpacePoints[nAddedClusters] = cluster;
6af4f584 282
283 nAddedClusters++;
284 } // end of clusters starting with 11=0x3
285 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
286 break;
287 }
288 } // end of loop over clusters
289
290 HLTDebug("Number of found clusters: %d", nAddedClusters);
291
292 outPtr->fSpacePointCnt = nAddedClusters;
293 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
294 mysize += nSize+sizeof(AliHLTTPCClusterData);
295
296 AliHLTComponentBlockData bd;
297 FillBlockData( bd );
298 bd.fOffset = offset;
299 bd.fSize = mysize;
300 bd.fSpecification = iter->fSpecification;
491d6af5 301
302 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
303 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
304
305 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
306
6af4f584 307 outputBlocks.push_back( bd );
308
a5dc9013 309 fBenchmark.AddOutput(bd.fSize);
310
6af4f584 311 tSize += mysize;
312 outBPtr += mysize;
6af4f584 313
314 } // end of loop over data blocks
a5dc9013 315
316 size = tSize;
317
318 fBenchmark.Stop(0);
319 HLTInfo(fBenchmark.GetStatistics());
320
321 return 0;
6af4f584 322} // end DoEvent()
84e36c27 323
324int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
325
326 // see header file for class documentation
327
328 if (argc<=0) return 0;
329 int i=0;
330 TString argument=argv[i];
331
332 if (argument.CompareTo("-solenoidBz")==0){
333 if (++i>=argc) return -EPROTO;
334 argument=argv[i];
335 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
336 if(!calib){
66a3e955 337 HLTError("CalibDB instance cannot be created.");
338 return 0;
84e36c27 339 }
340 Float_t magneticField = argument.Atof();
341 calib->SetExBField(magneticField);
342 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
343 return 2;
344 }
345
346 if (argument.CompareTo("-change-dataId")==0){
347 HLTDebug("Change data ID received.");
348 fDataId = kTRUE;
349 return 1;
350 }
58df4cfa 351
352 if (argument.CompareTo("-charge-threshold")==0) {
353 if (++i>=argc) return -EPROTO;
354 argument=argv[i];
5c2dca91 355 fChargeThreshold=(UInt_t)argument.Atoi();
58df4cfa 356 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
357 return 2;
358 }
84e36c27 359
360 // unknown argument
361 return -EINVAL;
362}
363
84e36c27 364int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
491d6af5 365 // see header file for class documentation
84e36c27 366 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
491d6af5 367}
6af4f584 368
369void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
370// see header file for class documentation
371
372 HLTInfo("The size is: %d", size);
373 for(Int_t n32bit=0; n32bit<size; n32bit++){
374
375 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
376 // cout << "word ptr initialized"<<endl;
377 for(Int_t w=3;w>=0;w--){
378 // cout <<"accessing word"<<endl;
379 AliHLTUInt8_t word = wordPtr[w];
380 // cout<< "word was accessed"<<endl;
381 for(int n=7; n>=0; n--){
382 //print the byte values
383 if((((word>>n)<<7)&0x80) != 0){
384 printf("1");
385 }
386 else{
387 printf("0");
388 }
389 }
390 printf(" ");
391 }
392 printf("\n");
393 }
394} // end of PrintDebug
1c29fee7 395
396void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap){
397// Get a list of OCDB object description needed for the particular component
398 if (!targetMap) return;
399 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
400}