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 int err = fTransform.Init( GetBz(), GetTimeStamp() );
114 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
119 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
121 if (iResult>=0 && argc>0)
122 iResult=ConfigureFromArgumentString(argc, argv);
127 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
128 // see header file for class documentation
132 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
133 const AliHLTComponentBlockData* blocks,
134 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
135 AliHLTUInt32_t& size,
136 vector<AliHLTComponentBlockData>& outputBlocks ){
137 // see header file for class documentation
139 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
144 fBenchmark.StartNewEvent();
147 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
149 const AliHLTComponentBlockData *iter = NULL;
152 AliHLTUInt8_t* outBPtr;
153 UInt_t offset, mysize, nSize, tSize = 0;
157 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
163 fBenchmark.AddInput(iter->fSize);
165 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
166 evtData.fEventID, evtData.fEventID,
167 DataType2Text( iter->fDataType).c_str(),
168 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
170 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
172 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
173 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
174 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
175 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
177 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
179 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
181 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outBPtr;
183 unsigned long maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
185 AliHLTUInt32_t *buffer;
186 buffer = (AliHLTUInt32_t*)iter->fPtr;
189 //cluster fabrication
190 buffer = new AliHLTUInt32_t[14];
192 buffer[0]=0xffffffff;
193 buffer[1]=0xffffffff;
194 buffer[2]=0xffffffff;
195 buffer[3]=0xffffffff;
196 buffer[4]=0xffffffff;
197 buffer[5]=0xffffffff;
198 buffer[6]=0xffffffff;
199 buffer[7]=0xffffffff;
201 buffer[8]=0xC60002EF;
207 buffer[13]=0x80000000;
210 // PrintDebug(buffer, 14);
212 // skip the first 8 32-bit CDH words
215 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
217 unsigned long nAddedClusters = 0;
219 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
220 // for(UInt_t nWords=0; nWords<5; nWords+=5){
222 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
223 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
226 if(bit3130 == 0x3){ //beginning of a cluster
228 //PrintDebug(&buffer[nWords], 5);
230 if(nAddedClusters>=maxPoints){
231 HLTWarning("No more space to add clusters, exiting!");
236 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
239 AliHLTUInt32_t rowCharge = buffer[nWords];
240 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
241 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
243 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
244 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
246 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
247 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
248 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
249 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
252 if(cluster.fCharge<fChargeThreshold) continue;
254 // correct expressions for the error calculation
255 // 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.
256 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
257 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
259 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);
261 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
264 fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
269 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
270 cluster.SetID( minSlice, minPartition, nAddedClusters );
272 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
273 outPtr->fSpacePoints[nAddedClusters] = cluster;
276 } // end of clusters starting with 11=0x3
277 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
280 } // end of loop over clusters
282 HLTDebug("Number of found clusters: %d", nAddedClusters);
284 outPtr->fSpacePointCnt = nAddedClusters;
285 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
286 mysize += nSize+sizeof(AliHLTTPCClusterData);
288 AliHLTComponentBlockData bd;
292 bd.fSpecification = iter->fSpecification;
294 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
295 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
297 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
299 outputBlocks.push_back( bd );
301 fBenchmark.AddOutput(bd.fSize);
306 } // end of loop over data blocks
311 HLTInfo(fBenchmark.GetStatistics());
316 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
318 // see header file for class documentation
320 if (argc<=0) return 0;
322 TString argument=argv[i];
324 if (argument.CompareTo("-solenoidBz")==0){
325 if (++i>=argc) return -EPROTO;
327 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
329 HLTError("CalibDB not available");
331 Float_t magneticField = argument.Atof();
332 calib->SetExBField(magneticField);
333 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
337 if (argument.CompareTo("-change-dataId")==0){
338 HLTDebug("Change data ID received.");
343 if (argument.CompareTo("-charge-threshold")==0) {
344 if (++i>=argc) return -EPROTO;
346 fChargeThreshold=(UInt_t)argument.Atoi();
347 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
355 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
356 // see header file for class documentation
357 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
360 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
361 // see header file for class documentation
363 HLTInfo("The size is: %d", size);
364 for(Int_t n32bit=0; n32bit<size; n32bit++){
366 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
367 // cout << "word ptr initialized"<<endl;
368 for(Int_t w=3;w>=0;w--){
369 // cout <<"accessing word"<<endl;
370 AliHLTUInt8_t word = wordPtr[w];
371 // cout<< "word was accessed"<<endl;
372 for(int n=7; n>=0; n--){
373 //print the byte values
374 if((((word>>n)<<7)&0x80) != 0){
385 } // end of PrintDebug
387 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap){
388 // Get a list of OCDB object description needed for the particular component
389 if (!targetMap) return;
390 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));