1 // $Id: AliHLTTPCHWClusterDecoderComponent.cxx 59611 2012-11-15 16:23:28Z sgorbuno $
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: Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de *
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 //***************************************************************************
20 /** @file AliHLTTPCHWClusterDecoderComponent.cxx
21 @author Sergey Gorbunov
26 #include "AliHLTTPCHWClusterDecoderComponent.h"
27 #include "AliHLTTPCHWClusterMergerV1.h"
28 #include "AliHLTTPCTransform.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTTPCSpacePointData.h"
31 #include "AliHLTTPCClusterDataFormat.h"
32 #include "AliHLTCDHWrapper.h"
33 #include "AliHLTTPCRawCluster.h"
34 #include "AliHLTTPCHWCFEmulator.h"
35 #include "AliHLTTPCHWCFData.h"
36 #include "AliHLTErrorGuard.h"
37 #include "AliHLTTPCRawClustersDescriptor.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBEntry.h"
43 #include "TObjString.h"
50 ClassImp(AliHLTTPCHWClusterDecoderComponent) //ROOT macro for the implementation of ROOT specific class methods
52 const char* AliHLTTPCHWClusterDecoderComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCHWClusterDecoder";
55 AliHLTTPCHWClusterDecoderComponent::AliHLTTPCHWClusterDecoderComponent()
58 fpClusterMerger(NULL),
60 fBenchmark("HWClusterDecoder")
62 // see header file for class documentation
64 // refer to README to build package
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69 fBenchmark.SetTimer(0,"total");
72 AliHLTTPCHWClusterDecoderComponent::~AliHLTTPCHWClusterDecoderComponent()
76 delete fpClusterMerger;
79 const char* AliHLTTPCHWClusterDecoderComponent::GetComponentID()
81 // see header file for class documentation
82 return "TPCHWClusterDecoder";
87 void AliHLTTPCHWClusterDecoderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
88 // see header file for class documentation
91 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC );
92 list.push_back( AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
95 AliHLTComponentDataType AliHLTTPCHWClusterDecoderComponent::GetOutputDataType() {
96 // see header file for class documentation
98 return kAliHLTMultipleDataType;
101 int AliHLTTPCHWClusterDecoderComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
102 // see header file for class documentation
105 tgtList.push_back( AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
106 tgtList.push_back( AliHLTTPCDefinitions::RawClustersDescriptorDataType() );
107 tgtList.push_back( AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
108 return tgtList.size();
111 void AliHLTTPCHWClusterDecoderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
112 // see header file for class documentation
114 inputMultiplier = 2.0;
117 AliHLTComponent* AliHLTTPCHWClusterDecoderComponent::Spawn() {
118 // see header file for class documentation
120 return new AliHLTTPCHWClusterDecoderComponent();
123 int AliHLTTPCHWClusterDecoderComponent::DoInit( int argc, const char** argv )
125 // see header file for class documentation
129 fpDecoder=new AliHLTTPCHWCFData;
130 if (!fpDecoder) iResult=-ENOMEM;
134 //!! if (iResult>=0) iResult = ConfigureFromCDBTObjString(fgkOCDBEntry);
136 if (iResult>=0 && argc>0) iResult = ConfigureFromArgumentString(argc, argv);
138 if ( iResult>=0 ) iResult = InitClusterMerger();
143 int AliHLTTPCHWClusterDecoderComponent::DoDeinit() {
144 // see header file for class documentation
145 if (!fpDecoder) delete fpDecoder;
147 delete fpClusterMerger;
148 fpClusterMerger = NULL;
152 int AliHLTTPCHWClusterDecoderComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
153 // see header file for class documentation
157 //!! iResult = ConfigureFromCDBTObjString(fgkOCDBEntry);
158 if ( iResult>=0 ) iResult = InitClusterMerger();
162 int AliHLTTPCHWClusterDecoderComponent::ScanConfigurationArgument(int argc, const char** argv){
164 // see header file for class documentation
166 if (argc<=0) return 0;
168 TString argument=argv[i];
170 if (argument.CompareTo("-do-merge")==0){
175 if (argument.CompareTo("-do-not-merge")==0){
184 int AliHLTTPCHWClusterDecoderComponent::InitClusterMerger()
190 if ( fDoMerge && !fpClusterMerger) {
191 fpClusterMerger = new AliHLTTPCHWClusterMergerV1;
192 if( !fpClusterMerger ) iResult=-ENOMEM;
193 else iResult = fpClusterMerger->Init();
195 HLTError("Can not initialise cluster merger");
196 delete fpClusterMerger;
203 void AliHLTTPCHWClusterDecoderComponent::GetOCDBObjectDescription( TMap* const targetMap)
205 // Get a list of OCDB object description needed for the particular component
206 if (!targetMap) return;
208 // OCDB entries for component arguments
210 //!! targetMap->Add(new TObjString(fgkOCDBEntry), new TObjString("component argument for HW cluster decoder"));
214 int AliHLTTPCHWClusterDecoderComponent::DoEvent(const AliHLTComponentEventData& evtData,
215 const AliHLTComponentBlockData* blocks,
216 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
217 AliHLTUInt32_t& size,
218 vector<AliHLTComponentBlockData>& outputBlocks ){
219 // see header file for class documentation
221 UInt_t maxOutSize = size;
224 if(!IsDataEvent()) return 0;
226 if (!fpDecoder) return -ENODEV;
228 fBenchmark.StartNewEvent();
231 AliHLTUInt8_t* origOutputPtr = outputPtr;
232 UInt_t origOutputBlocksSize = outputBlocks.size();
234 bool isInputPresent = kFALSE;
236 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
238 const AliHLTComponentBlockData *iter = blocks+ndx;
240 fBenchmark.AddInput(iter->fSize);
242 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
243 evtData.fEventID, evtData.fEventID,
244 DataType2Text( iter->fDataType).c_str(),
245 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
247 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
248 // simply forward MC labels
250 if( size+iter->fSize > maxOutSize ){
251 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
256 memcpy( outputPtr, iter->fPtr, iter->fSize );
258 AliHLTComponentBlockData bd;
261 bd.fSize = iter->fSize;
262 bd.fSpecification = iter->fSpecification;
263 bd.fDataType = iter->fDataType;
264 outputBlocks.push_back( bd );
266 outputPtr += bd.fSize;
267 fBenchmark.AddOutput(bd.fSize);
271 if( iter->fDataType == (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC) ){
275 HLTDebug("minSlice: %d, minPartition: %d", AliHLTTPCDefinitions::GetMinSliceNr(*iter), AliHLTTPCDefinitions::GetMinPatchNr(*iter));
277 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
279 if( maxRawClusters<=0 ) {
280 HLTWarning("No more space to add raw clusters, exiting!");
285 // copy raw cluster data from input
287 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
289 outputRaw->fVersion = 0;
290 outputRaw->fCount = 0;
292 AliHLTUInt32_t *buffer = (AliHLTUInt32_t*)iter->fPtr;
293 AliHLTCDHWrapper header(buffer);
295 // skip the first 8 32-bit CDH words
296 buffer += header.GetHeaderSize()/sizeof(AliHLTUInt32_t);
297 UInt_t bufferSize32 = ((Int_t)iter->fSize - header.GetHeaderSize() )/sizeof(AliHLTUInt32_t);
299 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
301 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
303 if(outputRaw->fCount>=maxRawClusters){
304 HLTWarning("No more space to add clusters, exiting!");
308 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
309 c.SetPadRow(cl.GetPadRow());
310 c.SetCharge(cl.GetCharge());
311 c.SetPad(cl.GetPad());
312 c.SetTime(cl.GetTime());
313 c.SetSigmaY2(cl.GetSigmaY2());
314 c.SetSigmaZ2(cl.GetSigmaZ2());
315 c.SetQMax(cl.GetQMax());
319 // fill into HLT output data
320 AliHLTComponentBlockData bdRawClusters;
321 FillBlockData( bdRawClusters );
322 bdRawClusters.fOffset = size;
323 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
324 bdRawClusters.fSpecification = iter->fSpecification;
325 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
326 outputBlocks.push_back( bdRawClusters );
327 fBenchmark.AddOutput(bdRawClusters.fSize);
328 size += bdRawClusters.fSize;
329 outputPtr += bdRawClusters.fSize;
332 } // end of loop over data blocks
334 AliHLTTPCRawClustersDescriptor desc;
335 desc.SetMergedClustersFlag(0);
337 if( fDoMerge && fpClusterMerger ){
338 fpClusterMerger->Clear();
339 fpClusterMerger->SetDataPointer(origOutputPtr);
340 for( UInt_t i=origOutputBlocksSize; i<outputBlocks.size(); i++){
341 fpClusterMerger->SetDataBlock(&(outputBlocks[i]));
343 int nMerged = fpClusterMerger->Merge();
344 fpClusterMerger->Clear();
345 desc.SetMergedClustersFlag(1);
346 HLTInfo("Merged %d clusters",nMerged);
349 // Write header block
350 if( isInputPresent ){
351 AliHLTComponent_BlockData bd;
354 bd.fSize = sizeof(AliHLTTPCRawClustersDescriptor);
355 bd.fDataType = AliHLTTPCDefinitions::RawClustersDescriptorDataType();
356 if( maxOutSize < size + bd.fSize ){
357 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+bd.fSize);
361 *(AliHLTTPCRawClustersDescriptor*)(outputPtr ) = desc;
362 outputBlocks.push_back(bd);
364 outputPtr += bd.fSize;
365 fBenchmark.AddOutput(bd.fSize);
366 HLTBenchmark("header data block of size %d", bd.fSize);
369 HLTInfo(fBenchmark.GetStatistics());
376 void AliHLTTPCHWClusterDecoderComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
377 // see header file for class documentation
379 HLTInfo("The size is: %d", size);
380 for(Int_t n32bit=0; n32bit<size; n32bit++){
382 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
383 // cout << "word ptr initialized"<<endl;
384 for(Int_t w=3;w>=0;w--){
385 // cout <<"accessing word"<<endl;
386 AliHLTUInt8_t word = wordPtr[w];
387 // cout<< "word was accessed"<<endl;
388 for(int n=7; n>=0; n--){
389 //print the byte values
390 if((((word>>n)<<7)&0x80) != 0){
401 } // end of PrintDebug