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
155 //!! iResult = ConfigureFromCDBTObjString(fgkOCDBEntry);
156 if ( iResult>=0 ) iResult = InitClusterMerger();
160 int AliHLTTPCHWClusterDecoderComponent::ScanConfigurationArgument(int argc, const char** argv){
162 // see header file for class documentation
164 if (argc<=0) return 0;
166 TString argument=argv[i];
168 if (argument.CompareTo("-do-merge")==0){
173 if (argument.CompareTo("-do-not-merge")==0){
182 int AliHLTTPCHWClusterDecoderComponent::InitClusterMerger()
188 if ( fDoMerge && !fpClusterMerger) {
189 fpClusterMerger = new AliHLTTPCHWClusterMergerV1;
190 if( !fpClusterMerger ) iResult=-ENOMEM;
191 else iResult = fpClusterMerger->Init();
193 HLTError("Can not initialise cluster merger");
194 delete fpClusterMerger;
201 void AliHLTTPCHWClusterDecoderComponent::GetOCDBObjectDescription( TMap* const targetMap)
203 // Get a list of OCDB object description needed for the particular component
204 if (!targetMap) return;
206 // OCDB entries for component arguments
208 //!! targetMap->Add(new TObjString(fgkOCDBEntry), new TObjString("component argument for HW cluster decoder"));
212 int AliHLTTPCHWClusterDecoderComponent::DoEvent(const AliHLTComponentEventData& evtData,
213 const AliHLTComponentBlockData* blocks,
214 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
215 AliHLTUInt32_t& size,
216 vector<AliHLTComponentBlockData>& outputBlocks ){
217 // see header file for class documentation
219 UInt_t maxOutSize = size;
222 if(!IsDataEvent()) return 0;
224 if (!fpDecoder) return -ENODEV;
226 fBenchmark.StartNewEvent();
229 AliHLTUInt8_t* origOutputPtr = outputPtr;
230 UInt_t origOutputBlocksSize = outputBlocks.size();
232 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
234 const AliHLTComponentBlockData *iter = blocks+ndx;
236 fBenchmark.AddInput(iter->fSize);
238 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
239 evtData.fEventID, evtData.fEventID,
240 DataType2Text( iter->fDataType).c_str(),
241 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
243 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
244 // simply forward MC labels
246 if( size+iter->fSize > maxOutSize ){
247 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
252 memcpy( outputPtr, iter->fPtr, iter->fSize );
254 AliHLTComponentBlockData bd;
257 bd.fSize = iter->fSize;
258 bd.fSpecification = iter->fSpecification;
259 bd.fDataType = iter->fDataType;
260 outputBlocks.push_back( bd );
262 outputPtr += bd.fSize;
263 fBenchmark.AddOutput(bd.fSize);
267 if( iter->fDataType == (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC) ){
269 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
270 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
272 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
273 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
275 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
277 if( maxRawClusters<=0 ) {
278 HLTWarning("No more space to add raw clusters, exiting!");
283 // copy raw cluster data from input
285 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
287 outputRaw->fVersion = 0;
288 outputRaw->fCount = 0;
290 AliHLTUInt32_t *buffer = (AliHLTUInt32_t*)iter->fPtr;
292 // skip the first 8 32-bit CDH words
294 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
296 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
298 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
300 if(outputRaw->fCount>=maxRawClusters){
301 HLTWarning("No more space to add clusters, exiting!");
305 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
306 c.SetPadRow(cl.GetPadRow());
307 c.SetCharge(cl.GetCharge());
308 c.SetPad(cl.GetPad());
309 c.SetTime(cl.GetTime());
310 c.SetSigmaY2(cl.GetSigmaY2());
311 c.SetSigmaZ2(cl.GetSigmaZ2());
312 c.SetQMax(cl.GetQMax());
316 // fill into HLT output data
317 AliHLTComponentBlockData bdRawClusters;
318 FillBlockData( bdRawClusters );
319 bdRawClusters.fOffset = size;
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 fpClusterMerger->SetDataPointer(origOutputPtr);
336 for( UInt_t i=origOutputBlocksSize; i<outputBlocks.size(); i++){
337 fpClusterMerger->SetDataBlock(&(outputBlocks[i]));
339 int nMerged = fpClusterMerger->Merge();
340 fpClusterMerger->Clear();
341 HLTInfo("Merged %d clusters",nMerged);
345 HLTInfo(fBenchmark.GetStatistics());
352 void AliHLTTPCHWClusterDecoderComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
353 // see header file for class documentation
355 HLTInfo("The size is: %d", size);
356 for(Int_t n32bit=0; n32bit<size; n32bit++){
358 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
359 // cout << "word ptr initialized"<<endl;
360 for(Int_t w=3;w>=0;w--){
361 // cout <<"accessing word"<<endl;
362 AliHLTUInt8_t word = wordPtr[w];
363 // cout<< "word was accessed"<<endl;
364 for(int n=7; n>=0; n--){
365 //print the byte values
366 if((((word>>n)<<7)&0x80) != 0){
377 } // end of PrintDebug