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"
33 #include "AliRawDataHeader.h"
35 #include "AliCDBManager.h"
36 #include "AliCDBEntry.h"
37 #include "AliTPCcalibDB.h"
40 #include "TObjString.h"
45 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
47 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
49 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
54 fBenchmark("HWClusterTransform")
56 // see header file for class documentation
58 // refer to README to build package
60 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63 fBenchmark.SetTimer(0,"total");
66 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
67 // see header file for class documentation
70 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
71 // see header file for class documentation
73 return "TPCHWClusterTransform";
76 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
77 // see header file for class documentation
80 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
83 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
84 // see header file for class documentation
86 return AliHLTTPCDefinitions::fgkClustersDataType;
89 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
90 // see header file for class documentation
93 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
94 return tgtList.size();
97 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
98 // see header file for class documentation
100 inputMultiplier = 3.0;
103 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
104 // see header file for class documentation
106 return new AliHLTTPCHWClusterTransformComponent();
109 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
110 // see header file for class documentation
112 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
114 HLTError("AliTPCcalibDB does not exist");
117 calib->SetRun(GetRunNo());
118 calib->UpdateRunInformations(GetRunNo());
120 int err = fTransform.Init( GetBz(), GetTimeStamp() );
123 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
128 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
130 if (iResult>=0 && argc>0)
131 iResult=ConfigureFromArgumentString(argc, argv);
136 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
137 // see header file for class documentation
141 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
142 const AliHLTComponentBlockData* blocks,
143 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
144 AliHLTUInt32_t& size,
145 vector<AliHLTComponentBlockData>& outputBlocks ){
146 // see header file for class documentation
148 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
153 fBenchmark.StartNewEvent();
156 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
158 const AliHLTComponentBlockData *iter = NULL;
161 AliHLTUInt8_t* outBPtr;
162 UInt_t offset, mysize, nSize, tSize = 0;
166 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
172 fBenchmark.AddInput(iter->fSize);
174 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
175 evtData.fEventID, evtData.fEventID,
176 DataType2Text( iter->fDataType).c_str(),
177 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
179 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
181 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
182 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
183 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
184 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
186 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
188 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
190 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outBPtr;
192 unsigned long maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
194 AliHLTUInt32_t *buffer;
195 buffer = (AliHLTUInt32_t*)iter->fPtr;
198 //cluster fabrication
199 buffer = new AliHLTUInt32_t[14];
201 buffer[0]=0xffffffff;
202 buffer[1]=0xffffffff;
203 buffer[2]=0xffffffff;
204 buffer[3]=0xffffffff;
205 buffer[4]=0xffffffff;
206 buffer[5]=0xffffffff;
207 buffer[6]=0xffffffff;
208 buffer[7]=0xffffffff;
210 buffer[8]=0xC60002EF;
216 buffer[13]=0x80000000;
219 // PrintDebug(buffer, 14);
221 // skip the first 8 32-bit CDH words
223 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
225 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
227 unsigned long nAddedClusters = 0;
229 for(UInt_t nWords=0; nWords<bufferSize32; nWords+=5){
230 // for(UInt_t nWords=0; nWords<5; nWords+=5){
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
236 if(bit3130 == 0x3){ //beginning of a cluster
238 //PrintDebug(&buffer[nWords], 5);
240 if(nAddedClusters>=maxPoints){
241 HLTWarning("No more space to add clusters, exiting!");
246 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
249 AliHLTUInt32_t rowCharge = buffer[nWords];
250 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
251 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
253 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
254 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
256 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
257 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
258 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
259 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
262 if(cluster.fCharge<fChargeThreshold) continue;
264 // correct expressions for the error calculation
265 // 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.
266 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
267 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
269 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);
271 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
274 fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
279 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
280 cluster.SetID( minSlice, minPartition, nAddedClusters );
282 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
283 outPtr->fSpacePoints[nAddedClusters] = cluster;
286 } // end of clusters starting with 11=0x3
287 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
290 } // end of loop over clusters
292 HLTDebug("Number of found clusters: %d", nAddedClusters);
294 outPtr->fSpacePointCnt = nAddedClusters;
295 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
296 mysize += nSize+sizeof(AliHLTTPCClusterData);
298 AliHLTComponentBlockData bd;
302 bd.fSpecification = iter->fSpecification;
304 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
305 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
307 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
309 outputBlocks.push_back( bd );
311 fBenchmark.AddOutput(bd.fSize);
316 } // end of loop over data blocks
321 HLTInfo(fBenchmark.GetStatistics());
326 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
328 // see header file for class documentation
330 if (argc<=0) return 0;
332 TString argument=argv[i];
334 if (argument.CompareTo("-solenoidBz")==0){
335 if (++i>=argc) return -EPROTO;
337 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
339 HLTError("CalibDB instance cannot be created.");
342 Float_t magneticField = argument.Atof();
343 calib->SetExBField(magneticField);
344 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
348 if (argument.CompareTo("-change-dataId")==0){
349 HLTDebug("Change data ID received.");
354 if (argument.CompareTo("-charge-threshold")==0) {
355 if (++i>=argc) return -EPROTO;
357 fChargeThreshold=(UInt_t)argument.Atoi();
358 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
366 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
367 // see header file for class documentation
368 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
371 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
372 // see header file for class documentation
374 HLTInfo("The size is: %d", size);
375 for(Int_t n32bit=0; n32bit<size; n32bit++){
377 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
378 // cout << "word ptr initialized"<<endl;
379 for(Int_t w=3;w>=0;w--){
380 // cout <<"accessing word"<<endl;
381 AliHLTUInt8_t word = wordPtr[w];
382 // cout<< "word was accessed"<<endl;
383 for(int n=7; n>=0; n--){
384 //print the byte values
385 if((((word>>n)<<7)&0x80) != 0){
396 } // end of PrintDebug
398 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap){
399 // Get a list of OCDB object description needed for the particular component
400 if (!targetMap) return;
401 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));