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