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 "AliCDBManager.h"
35 #include "AliCDBEntry.h"
36 #include "AliTPCcalibDB.h"
39 #include "TObjString.h"
44 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
46 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
48 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
53 fBenchmark("HWClusterTransform")
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 fBenchmark.SetTimer(0,"total");
65 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
66 // see header file for class documentation
69 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
70 // see header file for class documentation
72 return "TPCHWClusterTransform";
75 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
76 // see header file for class documentation
79 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
82 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
83 // see header file for class documentation
85 return AliHLTTPCDefinitions::fgkClustersDataType;
88 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
89 // see header file for class documentation
92 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
93 return tgtList.size();
96 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
97 // see header file for class documentation
99 inputMultiplier = 3.0;
102 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
103 // see header file for class documentation
105 return new AliHLTTPCHWClusterTransformComponent();
108 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
109 // see header file for class documentation
111 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
113 HLTError("AliTPCcalibDB does not exist");
116 calib->SetRun(GetRunNo());
117 calib->UpdateRunInformations(GetRunNo());
119 int err = fTransform.Init( GetBz(), GetTimeStamp() );
122 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
127 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
129 if (iResult>=0 && argc>0)
130 iResult=ConfigureFromArgumentString(argc, argv);
135 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
136 // see header file for class documentation
140 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
141 const AliHLTComponentBlockData* blocks,
142 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
143 AliHLTUInt32_t& size,
144 vector<AliHLTComponentBlockData>& outputBlocks ){
145 // see header file for class documentation
147 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
152 fBenchmark.StartNewEvent();
155 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
157 const AliHLTComponentBlockData *iter = NULL;
160 AliHLTUInt8_t* outBPtr;
161 UInt_t offset, mysize, nSize, tSize = 0;
165 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
171 fBenchmark.AddInput(iter->fSize);
173 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
174 evtData.fEventID, evtData.fEventID,
175 DataType2Text( iter->fDataType).c_str(),
176 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
178 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
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);
185 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
187 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
189 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outBPtr;
191 unsigned long maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
193 AliHLTUInt32_t *buffer;
194 buffer = (AliHLTUInt32_t*)iter->fPtr;
197 //cluster fabrication
198 buffer = new AliHLTUInt32_t[14];
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;
209 buffer[8]=0xC60002EF;
215 buffer[13]=0x80000000;
218 // PrintDebug(buffer, 14);
220 // skip the first 8 32-bit CDH words
223 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
225 unsigned long nAddedClusters = 0;
227 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
228 // for(UInt_t nWords=0; nWords<5; nWords+=5){
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
234 if(bit3130 == 0x3){ //beginning of a cluster
236 //PrintDebug(&buffer[nWords], 5);
238 if(nAddedClusters>=maxPoints){
239 HLTWarning("No more space to add clusters, exiting!");
244 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
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
251 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
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
254 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
255 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
256 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
257 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
260 if(cluster.fCharge<fChargeThreshold) continue;
262 // correct expressions for the error calculation
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])) );
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);
269 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
272 fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
277 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
278 cluster.SetID( minSlice, minPartition, nAddedClusters );
280 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
281 outPtr->fSpacePoints[nAddedClusters] = cluster;
284 } // end of clusters starting with 11=0x3
285 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
288 } // end of loop over clusters
290 HLTDebug("Number of found clusters: %d", nAddedClusters);
292 outPtr->fSpacePointCnt = nAddedClusters;
293 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
294 mysize += nSize+sizeof(AliHLTTPCClusterData);
296 AliHLTComponentBlockData bd;
300 bd.fSpecification = iter->fSpecification;
302 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
303 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
305 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
307 outputBlocks.push_back( bd );
309 fBenchmark.AddOutput(bd.fSize);
314 } // end of loop over data blocks
319 HLTInfo(fBenchmark.GetStatistics());
324 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
326 // see header file for class documentation
328 if (argc<=0) return 0;
330 TString argument=argv[i];
332 if (argument.CompareTo("-solenoidBz")==0){
333 if (++i>=argc) return -EPROTO;
335 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
337 HLTError("CalibDB not available");
339 Float_t magneticField = argument.Atof();
340 calib->SetExBField(magneticField);
341 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
345 if (argument.CompareTo("-change-dataId")==0){
346 HLTDebug("Change data ID received.");
351 if (argument.CompareTo("-charge-threshold")==0) {
352 if (++i>=argc) return -EPROTO;
354 fChargeThreshold=(UInt_t)argument.Atoi();
355 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
363 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
364 // see header file for class documentation
365 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
368 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
369 // see header file for class documentation
371 HLTInfo("The size is: %d", size);
372 for(Int_t n32bit=0; n32bit<size; n32bit++){
374 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
375 // cout << "word ptr initialized"<<endl;
376 for(Int_t w=3;w>=0;w--){
377 // cout <<"accessing word"<<endl;
378 AliHLTUInt8_t word = wordPtr[w];
379 // cout<< "word was accessed"<<endl;
380 for(int n=7; n>=0; n--){
381 //print the byte values
382 if((((word>>n)<<7)&0x80) != 0){
393 } // end of PrintDebug
395 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap){
396 // Get a list of OCDB object description needed for the particular component
397 if (!targetMap) return;
398 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));