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 "AliRawDataHeader.h"
33 #include "AliHLTTPCRawCluster.h"
34 #include "AliHLTTPCHWCFEmulator.h"
35 #include "AliHLTTPCHWCFData.h"
36 #include "AliHLTErrorGuard.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBEntry.h"
42 #include "TObjString.h"
49 ClassImp(AliHLTTPCHWClusterDecoderComponent) //ROOT macro for the implementation of ROOT specific class methods
51 const char* AliHLTTPCHWClusterDecoderComponent::fgkOCDBEntry="HLT/ConfigTPC/TPCHWClusterDecoder";
54 AliHLTTPCHWClusterDecoderComponent::AliHLTTPCHWClusterDecoderComponent()
57 fpClusterMerger(NULL),
59 fBenchmark("HWClusterDecoder")
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 fBenchmark.SetTimer(0,"total");
71 AliHLTTPCHWClusterDecoderComponent::~AliHLTTPCHWClusterDecoderComponent()
75 delete fpClusterMerger;
78 const char* AliHLTTPCHWClusterDecoderComponent::GetComponentID()
80 // see header file for class documentation
81 return "TPCHWClusterDecoder";
86 void AliHLTTPCHWClusterDecoderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
87 // see header file for class documentation
90 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC );
91 list.push_back( AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
94 AliHLTComponentDataType AliHLTTPCHWClusterDecoderComponent::GetOutputDataType() {
95 // see header file for class documentation
97 return kAliHLTMultipleDataType;
100 int AliHLTTPCHWClusterDecoderComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
101 // see header file for class documentation
104 tgtList.push_back( AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
105 tgtList.push_back( AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
106 return tgtList.size();
109 void AliHLTTPCHWClusterDecoderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
110 // see header file for class documentation
112 inputMultiplier = 2.0;
115 AliHLTComponent* AliHLTTPCHWClusterDecoderComponent::Spawn() {
116 // see header file for class documentation
118 return new AliHLTTPCHWClusterDecoderComponent();
121 int AliHLTTPCHWClusterDecoderComponent::DoInit( int argc, const char** argv )
123 // see header file for class documentation
127 fpDecoder=new AliHLTTPCHWCFData;
128 if (!fpDecoder) iResult=-ENOMEM;
132 if (iResult>=0) iResult = ConfigureFromCDBTObjString(fgkOCDBEntry);
134 if (iResult>=0 && argc>0) iResult = ConfigureFromArgumentString(argc, argv);
136 if ( iResult>=0 ) iResult = InitClusterMerger();
141 int AliHLTTPCHWClusterDecoderComponent::DoDeinit() {
142 // see header file for class documentation
143 if (!fpDecoder) delete fpDecoder;
145 delete fpClusterMerger;
146 fpClusterMerger = NULL;
150 int AliHLTTPCHWClusterDecoderComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
151 // see header file for class documentation
154 int iResult = ConfigureFromCDBTObjString(fgkOCDBEntry);
155 if ( iResult>=0 ) iResult = InitClusterMerger();
159 int AliHLTTPCHWClusterDecoderComponent::ScanConfigurationArgument(int argc, const char** argv){
161 // see header file for class documentation
163 if (argc<=0) return 0;
165 TString argument=argv[i];
167 if (argument.CompareTo("-do-merge")==0){
172 if (argument.CompareTo("-do-not-merge")==0){
181 int AliHLTTPCHWClusterDecoderComponent::InitClusterMerger()
187 if ( fDoMerge && !fpClusterMerger) {
188 fpClusterMerger = new AliHLTTPCHWClusterMergerV1;
189 if( !fpClusterMerger ) iResult=-ENOMEM;
190 else iResult = fpClusterMerger->Init();
192 HLTError("Can not initialise cluster merger");
193 delete fpClusterMerger;
200 void AliHLTTPCHWClusterDecoderComponent::GetOCDBObjectDescription( TMap* const targetMap)
202 // Get a list of OCDB object description needed for the particular component
203 if (!targetMap) return;
205 // OCDB entries for component arguments
207 targetMap->Add(new TObjString(fgkOCDBEntry), new TObjString("component argument for HW cluster decoder"));
211 int AliHLTTPCHWClusterDecoderComponent::DoEvent(const AliHLTComponentEventData& evtData,
212 const AliHLTComponentBlockData* blocks,
213 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
214 AliHLTUInt32_t& size,
215 vector<AliHLTComponentBlockData>& outputBlocks ){
216 // see header file for class documentation
218 UInt_t maxOutSize = size;
221 if(!IsDataEvent()) return 0;
223 if (!fpDecoder) return -ENODEV;
225 fBenchmark.StartNewEvent();
228 UInt_t outputBlocksSize = outputBlocks.size();
230 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
232 const AliHLTComponentBlockData *iter = blocks+ndx;
234 fBenchmark.AddInput(iter->fSize);
236 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
237 evtData.fEventID, evtData.fEventID,
238 DataType2Text( iter->fDataType).c_str(),
239 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
241 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
242 // simply forward MC labels
244 if( size+iter->fSize > maxOutSize ){
245 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
250 memcpy( outputPtr, iter->fPtr, iter->fSize );
252 AliHLTComponentBlockData bd;
255 bd.fSize = iter->fSize;
257 bd.fSpecification = iter->fSpecification;
258 bd.fDataType = iter->fDataType;
259 outputBlocks.push_back( bd );
261 outputPtr += bd.fSize;
262 fBenchmark.AddOutput(bd.fSize);
266 if( iter->fDataType == (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC) ){
268 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
269 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
271 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
272 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
274 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
276 if( maxRawClusters<=0 ) {
277 HLTWarning("No more space to add raw clusters, exiting!");
282 // copy raw cluster data from input
284 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
286 outputRaw->fVersion = 0;
287 outputRaw->fCount = 0;
289 AliHLTUInt32_t *buffer = (AliHLTUInt32_t*)iter->fPtr;
291 // skip the first 8 32-bit CDH words
293 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
295 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
297 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
299 if(outputRaw->fCount>=maxRawClusters){
300 HLTWarning("No more space to add clusters, exiting!");
304 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
305 c.SetPadRow(cl.GetPadRow());
306 c.SetCharge(cl.GetCharge());
307 c.SetPad(cl.GetPad());
308 c.SetTime(cl.GetTime());
309 c.SetSigmaY2(cl.GetSigmaY2());
310 c.SetSigmaZ2(cl.GetSigmaZ2());
311 c.SetQMax(cl.GetQMax());
315 // fill into HLT output data
316 AliHLTComponentBlockData bdRawClusters;
317 FillBlockData( bdRawClusters );
318 bdRawClusters.fOffset = size;
319 bdRawClusters.fPtr = outputPtr;
320 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
321 bdRawClusters.fSpecification = iter->fSpecification;
322 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
323 outputBlocks.push_back( bdRawClusters );
324 fBenchmark.AddOutput(bdRawClusters.fSize);
325 size += bdRawClusters.fSize;
326 outputPtr += bdRawClusters.fSize;
328 continue; // HW clusters data block
331 } // end of loop over data blocks
333 if( fDoMerge && fpClusterMerger ){
334 fpClusterMerger->Clear();
335 for( UInt_t i=outputBlocksSize; i<outputBlocks.size(); i++){
336 fpClusterMerger->SetDataBlock(&(outputBlocks[i]));
338 int nMerged = fpClusterMerger->Merge();
339 fpClusterMerger->Clear();
340 HLTInfo("Merged %d clusters",nMerged);
344 HLTInfo(fBenchmark.GetStatistics());
351 void AliHLTTPCHWClusterDecoderComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
352 // see header file for class documentation
354 HLTInfo("The size is: %d", size);
355 for(Int_t n32bit=0; n32bit<size; n32bit++){
357 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
358 // cout << "word ptr initialized"<<endl;
359 for(Int_t w=3;w>=0;w--){
360 // cout <<"accessing word"<<endl;
361 AliHLTUInt8_t word = wordPtr[w];
362 // cout<< "word was accessed"<<endl;
363 for(int n=7; n>=0; n--){
364 //print the byte values
365 if((((word>>n)<<7)&0x80) != 0){
376 } // end of PrintDebug