1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
5 * Primary Authors: Kenneth Aamodt <Kenneth.Aamodt@student.uib.no> *
6 * for The ALICE HLT Project. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 /** @file AliHLTTPCHWCFDataReverterComponent.cxx
18 @author Kenneth Aamodt
20 @brief Component for reverting data for the HW clusterfinder
23 // see header file for class documentation //
25 // refer to README to build package //
27 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
32 #include "AliHLTTPCHWCFDataReverterComponent.h"
33 #include "AliHLTTPCDigitReaderDecoder.h"
34 #include "AliHLTTPCTransform.h"
35 #include "AliHLTTPCDefinitions.h"
36 #include "AliHLTTPCDigitData.h"
37 #include "AliHLTTPCMapping.h"
43 #include "AliHLTAltroEncoder.h"
44 #include "AliRawDataHeader.h"
46 /** ROOT macro for the implementation of ROOT specific class methods */
47 ClassImp(AliHLTTPCHWCFDataReverterComponent)
49 AliHLTTPCHWCFDataReverterComponent::AliHLTTPCHWCFDataReverterComponent()
53 fNumberOfPadsInRow(NULL),
60 fVectorInitialized(kFALSE),
63 // see header file for class documentation
65 // refer to README to build package
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 AliHLTTPCHWCFDataReverterComponent::~AliHLTTPCHWCFDataReverterComponent()
72 // see header file for class documentation
73 if(fVectorInitialized){
74 DeInitializePadArray();
76 if(fNumberOfPadsInRow){
77 delete [] fNumberOfPadsInRow;
78 fNumberOfPadsInRow=NULL;
81 delete [] fFirstPadHigh;
94 // Public functions to implement AliHLTComponent's interface.
95 // These functions are required for the registration process
97 const char* AliHLTTPCHWCFDataReverterComponent::GetComponentID()
99 // see header file for class documentation
100 return "TPCHWCFDataReverter";
103 void AliHLTTPCHWCFDataReverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
105 // see header file for class documentation
107 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
110 AliHLTComponentDataType AliHLTTPCHWCFDataReverterComponent::GetOutputDataType()
112 // see header file for class documentation
113 return kAliHLTDataTypeDDLRaw;
116 int AliHLTTPCHWCFDataReverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
118 // see header file for class documentation
120 tgtList.push_back(kAliHLTDataTypeDDLRaw);
121 return tgtList.size();
124 void AliHLTTPCHWCFDataReverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 // see header file for class documentation
131 AliHLTComponent* AliHLTTPCHWCFDataReverterComponent::Spawn()
133 // see header file for class documentation
134 return new AliHLTTPCHWCFDataReverterComponent();
137 int AliHLTTPCHWCFDataReverterComponent::DoInit( int argc, const char** argv )
139 // see header file for class documentation
146 // -- number of timebins
147 if ( !strcmp( argv[i], "-timebins" )) {
148 fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
149 AliHLTTPCTransform::SetNTimeBins(fNTimeBins);
151 HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
158 HLTError("HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
163 HLTDebug("using AliHLTTPCDigitReaderDecoder");
164 fDigitReader = new AliHLTTPCDigitReaderDecoder();
169 int AliHLTTPCHWCFDataReverterComponent::DoDeinit()
171 // see header file for class documentation
175 Int_t AliHLTTPCHWCFDataReverterComponent::DeInitializePadArray()
177 // see header file for class documentation
178 if(fVectorInitialized){
179 for(Int_t i=0;i<fNumberOfRows;i++){
180 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
181 delete fRowPadVector[i][j];
182 fRowPadVector[i][j]=NULL;
184 fRowPadVector[i].clear();
186 fRowPadVector.clear();
191 void AliHLTTPCHWCFDataReverterComponent::InitializePadArray(){
192 // see header file for class documentation
194 HLTFatal("Patch is not set");
198 fFirstRow = AliHLTTPCTransform::GetFirstRow(fCurrentPatch);
199 fLastRow = AliHLTTPCTransform::GetLastRow(fCurrentPatch);
201 fNumberOfRows=fLastRow-fFirstRow+1;
202 fNumberOfPadsInRow= new Int_t[fNumberOfRows];
203 fFirstPadHigh= new Int_t[fNumberOfRows];
205 memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
206 memset( fFirstPadHigh, 0, sizeof(Int_t)*(fNumberOfRows));
208 for(Int_t i=0;i<fNumberOfRows;i++){
209 fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
210 AliHLTTPCPadVector tmpRow;
211 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
212 AliHLTTPCPad *tmpPad = new AliHLTTPCPad();
213 if(fFirstPadHigh[i] != 0){
214 if(fMapping->GetHwAddress(i,j) > 2047){
219 tmpRow.push_back(tmpPad);
221 fRowPadVector.push_back(tmpRow);
223 fVectorInitialized=kTRUE;
227 int AliHLTTPCHWCFDataReverterComponent::DoEvent( const AliHLTComponentEventData& evtData,
228 const AliHLTComponentBlockData* blocks,
229 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
230 AliHLTUInt32_t& size,
231 vector<AliHLTComponentBlockData>& outputBlocks )
233 // see header file for class documentation
235 if (!fDigitReader) return -ENODEV;
237 AliHLTUInt32_t capacity=size;
239 if (!IsDataEvent()) return 0;
241 // == init iter (pointer to datablock)
242 const AliHLTComponentBlockData* iter = NULL;
246 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
250 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
251 evtData.fEventID, evtData.fEventID,
252 DataType2Text( iter->fDataType).c_str(),
253 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
255 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)){
259 if (iter->fSize<=sizeof(AliRawDataHeader)) {
260 // forward empty DDLs
261 outputBlocks.push_back(*iter);
265 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
266 UInt_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
268 if(fDigitReader->InitBlock(iter->fPtr,iter->fSize,patch,slice)<0){
269 HLTWarning("Decoder failed to initialize, event aborted.");
273 fMapping = new AliHLTTPCMapping(patch);
275 if(!fVectorInitialized){
277 InitializePadArray();
280 //Here the reading of the data and the zerosuppression takes place
281 while(fDigitReader->NextChannel()){//Pad
283 Int_t row=fDigitReader->GetRow();
284 Int_t pad=fDigitReader->GetPad();
286 if(row >= fNumberOfRows || row < 0){
289 else if(pad >= fNumberOfPadsInRow[row] || pad < 0){
293 AliHLTTPCPad *tmpPad = fRowPadVector[row][pad];
295 tmpPad->SetDataToDefault();
298 //reading data to pad
299 while(fDigitReader->NextBunch()){
300 const UInt_t *bunchData= fDigitReader->GetSignals();
301 Int_t time=fDigitReader->GetTime();
302 for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
303 if(bunchData[i]>0){// disregarding 0 data.
304 if(time+i >= 0 && time+i < AliHLTTPCTransform::GetNTimeBins()){
306 tmpPad->SetDataSignal(time+i,bunchData[i]);
314 if( iter->fSize > sizeof(AliRawDataHeader )){
316 AliHLTAltroEncoder *altroEncoder = new AliHLTAltroEncoder;
317 altroEncoder->SetBuffer(outputPtr,capacity); //tests if one overwrite the buffer is done in the encoder
319 // set CDH from the beginning of buffer
320 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
322 UChar_t *RCUTrailer=NULL;
323 Int_t RCUTrailerSize=fDigitReader->GetRCUTrailerSize();
324 if (RCUTrailerSize<=0 || !fDigitReader->GetRCUTrailerData( RCUTrailer )) {
325 if(RCUTrailer==NULL){
326 HLTWarning("can not find RCU trailer for data block %s 0x%08x: skipping data block",
327 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
331 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
333 for(Int_t row = 0; row< fNumberOfRows;row++){
334 Int_t padHigh=fFirstPadHigh[row];
337 Int_t padHighIndex= padHigh;
339 while(padLowIndex < padHigh || padHighIndex < fNumberOfPadsInRow[row]){
340 Int_t currentTime = 0;
342 //add the data from low side
343 if(padLowIndex < padHigh){
344 AliHLTTPCPad * lowPad= fRowPadVector[row][padLowIndex];
345 while(lowPad->GetNextGoodSignal(currentTime, bunchSize)){
346 for(Int_t i=0;i<bunchSize;i++){
347 if (altroEncoder->AddSignal((AliHLTUInt16_t)(lowPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
348 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
349 slice, patch, fMapping->GetHwAddress(row,padLowIndex), row, padLowIndex, currentTime+i, bunchSize);
354 altroEncoder->SetChannel(fMapping->GetHwAddress(row,padLowIndex));
358 //add the data from the high side
359 if(padHighIndex < fNumberOfPadsInRow[row]){
360 AliHLTTPCPad * highPad= fRowPadVector[row][padHighIndex];
361 while(highPad->GetNextGoodSignal(currentTime, bunchSize)){
362 for(Int_t i=0;i<bunchSize;i++){
363 if (altroEncoder->AddSignal((AliHLTUInt16_t)(highPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
364 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
365 slice, patch, fMapping->GetHwAddress(row,padHighIndex), row, padHighIndex, currentTime+i, bunchSize);
370 altroEncoder->SetChannel(fMapping->GetHwAddress(row,padHighIndex));
377 altroEncoder->Revert40BitWords(sizeof(AliRawDataHeader),RCUTrailerSize);
379 int sizeOfData=altroEncoder->SetLength();
382 HLTError("data encoding failed");
386 if(sizeOfData>(int)capacity){
387 HLTWarning("Buffer too small too add the altrodata: %d of %d byte(s) already used", sizeOfData, capacity);
392 AliHLTComponentBlockData bd;
395 bd.fSize = sizeOfData;
396 bd.fDataType = kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC;
397 bd.fSpecification = iter->fSpecification;
398 outputBlocks.push_back( bd );
402 fDigitReader->Reset();
406 fDigitReader->Reset();
409 HLTDebug("Total size of output is: %d ",size);