]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
initialisation bug fixed
[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"
36
2b727eff 37#include "TMath.h"
6af4f584 38#include <cstdlib>
39#include <cerrno>
40#include <sys/time.h>
41
42ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
43
44AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
a9d14303 45:
46fOfflineTransform(NULL)
6af4f584 47{
48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
a9d14303 52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53
6af4f584 54}
55
56AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
57// see header file for class documentation
58}
59
60const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
61// see header file for class documentation
62
63 return "TPCHWClusterTransform";
64}
65
66void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
67 // see header file for class documentation
68
69 list.clear();
70 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
71}
72
73AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
74 // see header file for class documentation
75
76 return AliHLTTPCDefinitions::fgkClustersDataType;
77}
78
79int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
80 // see header file for class documentation
81
82 tgtList.clear();
83 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
84 return tgtList.size();
85}
86
87void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
88 // see header file for class documentation
89
90 constBase = 0;
91 inputMultiplier = 2.0;
92}
93
94AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
95 // see header file for class documentation
96
97 return new AliHLTTPCHWClusterTransformComponent();
98}
99
100int AliHLTTPCHWClusterTransformComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
101// see header file for class documentation
102
b4c689c4 103 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
104 if(!pCalib ||
105 !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
106 HLTError("Can not retrieve Offline transform from AliTPCcalibDB (%p)", pCalib);
107 return -ENOENT;
108 }
109
6af4f584 110// Int_t i = 0;
111// Char_t* cpErr;
112//
113// int iResult=0;
114//
115// TString configuration="";
116// TString argument="";
117// for (int j=0; j<argc && iResult>=0; j++) {
118//
119// argument=argv[j];
120// if (!configuration.IsNull()) configuration+=" ";
121// configuration+=argument;
122// }
123//
124// if (!configuration.IsNull()) {
125// iResult=Configure(configuration.Data());
126// } else {
127// iResult=Reconfigure(NULL, NULL);
128// }
129
130 return 0;
131} // end DoInit()
132
133int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
134 // see header file for class documentation
135
136 return 0;
137}
138
139int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
140 const AliHLTComponentBlockData* blocks,
141 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
142 AliHLTUInt32_t& size,
143 vector<AliHLTComponentBlockData>& outputBlocks ){
144 // see header file for class documentation
145
146 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
147 size = 0;
148 return 0;
149 }
150
151 const AliHLTComponentBlockData *iter = NULL;
152 unsigned long ndx;
153
154 AliHLTTPCClusterData* outPtr;
155
156 AliHLTUInt8_t* outBPtr;
157 UInt_t offset, mysize, nSize, tSize = 0;
158
159 outBPtr = outputPtr;
160 outPtr = (AliHLTTPCClusterData*)outBPtr;
161
162 AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
163
164 unsigned long maxPoints = 0;
165
166 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
167
168 iter = blocks+ndx;
169 mysize = 0;
170 offset = tSize;
171
172 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
173 evtData.fEventID, evtData.fEventID,
174 DataType2Text( iter->fDataType).c_str(),
175 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
176
177 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
178
179 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
180 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
181 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
182 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
183
184 outPtr = (AliHLTTPCClusterData*)outBPtr;
185 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
186
187 AliHLTUInt32_t *buffer;
188 buffer = (AliHLTUInt32_t*)iter->fPtr;
189
190 /*
191 //cluster fabrication
192 buffer = new AliHLTUInt32_t[14];
193 //header
194 buffer[0]=0xffffffff;
195 buffer[1]=0xffffffff;
196 buffer[2]=0xffffffff;
197 buffer[3]=0xffffffff;
198 buffer[4]=0xffffffff;
199 buffer[5]=0xffffffff;
200 buffer[6]=0xffffffff;
201 buffer[7]=0xffffffff;
202 //cluster 1
203 buffer[8]=0xC60002EF;
204 buffer[9]=0x0;
205 buffer[10]=0x0;
206 buffer[11]=0x0;
207 buffer[12]=0x0;
208 //RCU trailer
209 buffer[13]=0x80000000;
210 */
211
212 Int_t sector=-99, thisrow=-99;
213
214 // PrintDebug(buffer, 14);
215
216 // skip the first 8 32-bit CDH words
217 buffer += 8;
218
219 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
220
221 unsigned long nAddedClusters = 0;
222
223 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
224 // for(UInt_t nWords=0; nWords<5; nWords+=5){
225
226 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
227 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
228
229 if(bit3130 == 0x3){ //beginning of a cluster
230
231 //PrintDebug(&buffer[nWords], 5);
232
233 if(nAddedClusters>=maxPoints){
234 HLTWarning("No more space to add clusters, exiting!");
235 break;
236 }
237
238 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
239
240 //get the first word
241 AliHLTUInt32_t rowCharge = buffer[nWords];
242 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
243 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
244
245 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
2b727eff 246 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
247 cluster.fSigmaY2 = (Float_t)buffer[nWords+3];
6af4f584 248 cluster.fSigmaZ2 = (Float_t)buffer[nWords+4];
2b727eff 249
250 // correct expressions for the error calculation
251
252 //cluster.fSigmaY2 = TMath::Sqrt( (Float_t)buffer[nWords+3] - (Float_t)buffer[nWords+1]*(Float_t)buffer[nWords+1] );
253 //cluster.fSigmaY2 = TMath::Sqrt( (Float_t)buffer[nWords+3] - (Float_t)buffer[nWords+1]*(Float_t)buffer[nWords+1] );
254
255
256
257 HLTInfo("padrow: %d, charge: %f, pad: %d, time: %d", cluster.fPadRow, (Float_t)cluster.fCharge, (Float_t)buffer[nWords+1], (Float_t)buffer[nWords+2]);
258
6af4f584 259 Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
a9d14303 260
2b727eff 261 // if(fOfflineTransform == NULL){
a9d14303 262 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
263 AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);
264 AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, (Float_t)buffer[nWords+1], (Float_t)buffer[nWords+2]);
265 if(minSlice>17) xyz[1]=(-1)*xyz[1];
266 cluster.fX = xyz[0];
267 cluster.fY = xyz[1];
268 cluster.fZ = xyz[2];
a9d14303 269
2b727eff 270// } else {
271//
272// HLTInfo("padrow: %d, pad: %d", cluster.fPadRow, buffer[nWords+1]);
273//
274// Double_t x[3] = {thisrow, (Float_t)buffer[nWords+1]+.5, (Float_t)buffer[nWords+2]};
275// Int_t iSector[1]= {sector};
276// fOfflineTransform->Transform(x,iSector,0,1);
277// cluster.fX = x[0];
278// cluster.fY = x[1];
279// cluster.fZ = x[2];
280//
281// }
a9d14303 282// cluster.fX = xyz[0];
283// cluster.fY = xyz[1];
284// cluster.fZ = xyz[2];
6af4f584 285
2b727eff 286 //HLTInfo("X: %f, Y: %f, Z: %f, Charge: %d", cluster.fX,cluster.fY,cluster.fZ, cluster.fCharge);
6af4f584 287
288 spacePoints[nAddedClusters] = cluster;
289
290 nAddedClusters++;
291 } // end of clusters starting with 11=0x3
292 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
293 break;
294 }
295 } // end of loop over clusters
296
297 HLTDebug("Number of found clusters: %d", nAddedClusters);
298
299 outPtr->fSpacePointCnt = nAddedClusters;
300 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
301 mysize += nSize+sizeof(AliHLTTPCClusterData);
302
303 AliHLTComponentBlockData bd;
304 FillBlockData( bd );
305 bd.fOffset = offset;
306 bd.fSize = mysize;
307 bd.fSpecification = iter->fSpecification;
308 bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
309 outputBlocks.push_back( bd );
310
311 tSize += mysize;
312 outBPtr += mysize;
313 outPtr = (AliHLTTPCClusterData*)outBPtr;
314
315 } // end of loop over data blocks
316 size = tSize;
317 return 0;
318} // end DoEvent()
319
320// int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) {
321// // see header file for class documentation
322//
323// int iResult=0;
324// if (!arguments) return iResult;
325// HLTInfo("parsing configuration string \'%s\'", arguments);
326//
327// TString allArgs=arguments;
328// TString argument;
329// int bMissingParam=0;
330//
331// TObjArray* pTokens=allArgs.Tokenize(" ");
332// if (pTokens) {
333// for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
334// argument=((TObjString*)pTokens->At(i))->GetString();
335// if (argument.IsNull()) continue;
336//
337// if (argument.CompareTo("-sum-noise-histograms")==0) {
338// fNoiseHistograms = kTRUE;
339// HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
340//
341// } else if (argument.CompareTo("-sum-krypton-histograms")==0) {
342// fKryptonHistograms = kTRUE;
343// HLTInfo("got \'-sum-krypton-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
344//
345// } else if (argument.CompareTo("-use-general")==0) {
346// fUseGeneral = kTRUE;
347// HLTInfo("got \'-use-general\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
348//
349// } else if (argument.CompareTo("-ignore-specification")==0) {
350// fIgnoreSpecification = kTRUE;
351// HLTInfo("got \'-ignore-specification\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
352// }
353// else {
354// HLTError("unknown argument %s", argument.Data());
355// iResult=-EINVAL;
356// break;
357// }
358// } // end for
359//
360//
361// delete pTokens;
362//
363// } // end if pTokens
364//
365// if (bMissingParam) {
366// HLTError("missing parameter for argument %s", argument.Data());
367// iResult=-EINVAL;
368// }
369// return iResult;
370// }
371
372// int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
373// // see header file for class documentation
374//
375// int iResult=0;
376// const char* path="HLT/ConfigTPC/TPCHistogramHandlerComponent";
377// const char* defaultNotify="";
378// if (cdbEntry) {
379// path=cdbEntry;
380// defaultNotify=" (default)";
381// }
382//
383// if (path) {
384// HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
385// AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
386// if (pEntry) {
387// TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
388// if (pString) {
389// HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
390// iResult=Configure(pString->GetString().Data());
391// } else {
392// HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
393// }
394// } else {
395// HLTError("cannot fetch object \"%s\" from CDB", path);
396// }
397// }
398// return iResult;
399// }
400
401
402void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
403// see header file for class documentation
404
405 HLTInfo("The size is: %d", size);
406 for(Int_t n32bit=0; n32bit<size; n32bit++){
407
408 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
409 // cout << "word ptr initialized"<<endl;
410 for(Int_t w=3;w>=0;w--){
411 // cout <<"accessing word"<<endl;
412 AliHLTUInt8_t word = wordPtr[w];
413 // cout<< "word was accessed"<<endl;
414 for(int n=7; n>=0; n--){
415 //print the byte values
416 if((((word>>n)<<7)&0x80) != 0){
417 printf("1");
418 }
419 else{
420 printf("0");
421 }
422 }
423 printf(" ");
424 }
425 printf("\n");
426 }
427} // end of PrintDebug