3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTPCHWClusterTransformComponent.cxx
20 @author Kalliopi Kanaki
28 #include "AliHLTTPCHWClusterTransformComponent.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTTPCTransform.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCClusterDataFormat.h"
34 #include "AliTPCcalibDB.h"
35 #include "AliTPCTransform.h"
36 #include "AliTPCCalPad.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBEntry.h"
42 #include "TObjString.h"
47 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
49 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
51 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
53 fOfflineTransform(NULL),
55 fOfflineTPCRecoParam()
57 // see header file for class documentation
59 // refer to README to build package
61 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
65 // see header file for class documentation
68 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
69 // see header file for class documentation
71 return "TPCHWClusterTransform";
74 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
75 // see header file for class documentation
78 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
81 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
82 // see header file for class documentation
84 return AliHLTTPCDefinitions::fgkClustersDataType;
87 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
88 // see header file for class documentation
91 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
92 return tgtList.size();
95 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
96 // see header file for class documentation
98 inputMultiplier = 3.0;
101 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
102 // see header file for class documentation
104 return new AliHLTTPCHWClusterTransformComponent();
107 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
108 // see header file for class documentation
110 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
112 !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
113 HLTError("Cannot retrieve offline transform from AliTPCcalibDB (%p)", pCalib);
116 // set the flags in the reco param
117 fOfflineTPCRecoParam.SetUseExBCorrection(1);
118 fOfflineTPCRecoParam.SetUseTOFCorrection(1);
119 fOfflineTransform->SetCurrentRecoParam(&fOfflineTPCRecoParam);
121 pCalib->SetExBField(GetBz());
128 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
130 if (iResult>=0 && argc>0)
131 iResult=ConfigureFromArgumentString(argc, argv);
136 TString configuration="";
138 for(int j=0; j<argc && iResult>=0; j++){
140 if (!configuration.IsNull()) configuration+=" ";
141 configuration+=argument;
144 if (!configuration.IsNull()) {
145 iResult=Configure(configuration.Data());
148 //iResult=Reconfigure(NULL, NULL);
155 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
156 // see header file for class documentation
161 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
162 const AliHLTComponentBlockData* blocks,
163 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
164 AliHLTUInt32_t& size,
165 vector<AliHLTComponentBlockData>& outputBlocks ){
166 // see header file for class documentation
167 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
171 const AliHLTComponentBlockData *iter = NULL;
174 AliHLTTPCClusterData* outPtr;
176 AliHLTUInt8_t* outBPtr;
177 UInt_t offset, mysize, nSize, tSize = 0;
180 outPtr = (AliHLTTPCClusterData*)outBPtr;
182 AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
184 unsigned long maxPoints = 0;
186 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
192 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
193 evtData.fEventID, evtData.fEventID,
194 DataType2Text( iter->fDataType).c_str(),
195 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
197 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
199 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
200 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
201 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
202 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
204 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
206 outPtr = (AliHLTTPCClusterData*)outBPtr;
207 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
209 AliHLTUInt32_t *buffer;
210 buffer = (AliHLTUInt32_t*)iter->fPtr;
213 //cluster fabrication
214 buffer = new AliHLTUInt32_t[14];
216 buffer[0]=0xffffffff;
217 buffer[1]=0xffffffff;
218 buffer[2]=0xffffffff;
219 buffer[3]=0xffffffff;
220 buffer[4]=0xffffffff;
221 buffer[5]=0xffffffff;
222 buffer[6]=0xffffffff;
223 buffer[7]=0xffffffff;
225 buffer[8]=0xC60002EF;
231 buffer[13]=0x80000000;
234 Int_t sector=-99, thisrow=-99;
236 // PrintDebug(buffer, 14);
238 // skip the first 8 32-bit CDH words
241 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
243 unsigned long nAddedClusters = 0;
245 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
246 // for(UInt_t nWords=0; nWords<5; nWords+=5){
248 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
249 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
252 if(bit3130 == 0x3){ //beginning of a cluster
254 //PrintDebug(&buffer[nWords], 5);
256 if(nAddedClusters>=maxPoints){
257 HLTWarning("No more space to add clusters, exiting!");
261 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
265 AliHLTUInt32_t rowCharge = buffer[nWords];
266 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
267 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
270 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
271 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
274 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
275 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
276 //cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
277 //cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
279 // correct expressions for the error calculation
280 // 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.
281 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
282 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
284 Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
286 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);
289 if(fOfflineTransform == NULL){
291 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
292 AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);
293 AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, tmpPad, tmpTime);
294 if(minSlice>17) xyz[1]=(-1)*xyz[1];
301 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
302 AliHLTTPCTransform::Slice2Sector(minSlice, (UInt_t)cluster.fPadRow, sector, thisrow);
303 Double_t x[3] = {(Double_t)cluster.fPadRow,tmpPad+.5,tmpTime};
304 Int_t iSector[1]= {sector};
305 fOfflineTransform->Transform(x,iSector,0,1);
312 HLTDebug("cluster X: %f, Y: %f, Z: %f \n", cluster.fX, cluster.fY, cluster.fZ);
313 spacePoints[nAddedClusters] = cluster;
316 } // end of clusters starting with 11=0x3
317 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
320 } // end of loop over clusters
322 HLTDebug("Number of found clusters: %d", nAddedClusters);
324 outPtr->fSpacePointCnt = nAddedClusters;
325 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
326 mysize += nSize+sizeof(AliHLTTPCClusterData);
328 AliHLTComponentBlockData bd;
332 bd.fSpecification = iter->fSpecification;
334 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
335 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
337 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
339 outputBlocks.push_back( bd );
343 outPtr = (AliHLTTPCClusterData*)outBPtr;
345 } // end of loop over data blocks
350 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
352 // see header file for class documentation
354 if (argc<=0) return 0;
356 TString argument=argv[i];
358 if (argument.CompareTo("-solenoidBz")==0){
359 if (++i>=argc) return -EPROTO;
361 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
363 HLTError("CalibDB not availible");
365 Float_t magneticField = argument.Atof();
366 calib->SetExBField(magneticField);
367 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
371 if (argument.CompareTo("-change-dataId")==0){
372 HLTDebug("Change data ID received.");
383 int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) {
384 // see header file for class documentation
387 if (!arguments) return iResult;
388 HLTInfo("parsing configuration string \'%s\'", arguments);
390 TString allArgs=arguments;
394 TObjArray* pTokens=allArgs.Tokenize(" ");
396 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
397 argument=((TObjString*)pTokens->At(i))->GetString();
398 if (argument.IsNull()) continue;
400 if (argument.CompareTo("-change-dataId")==0) {
402 HLTInfo("got \'-change-dataId\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
405 HLTError("unknown argument %s", argument.Data());
416 HLTError("missing parameter for argument %s", argument.Data());
422 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
423 // see header file for class documentation
424 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
427 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
428 // see header file for class documentation
430 HLTInfo("The size is: %d", size);
431 for(Int_t n32bit=0; n32bit<size; n32bit++){
433 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
434 // cout << "word ptr initialized"<<endl;
435 for(Int_t w=3;w>=0;w--){
436 // cout <<"accessing word"<<endl;
437 AliHLTUInt8_t word = wordPtr[w];
438 // cout<< "word was accessed"<<endl;
439 for(int n=7; n>=0; n--){
440 //print the byte values
441 if((((word>>n)<<7)&0x80) != 0){
452 } // end of PrintDebug