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),
64 // see header file for class documentation
66 // refer to README to build package
68 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
71 AliHLTTPCHWCFDataReverterComponent::~AliHLTTPCHWCFDataReverterComponent()
73 // see header file for class documentation
74 if(fVectorInitialized){
75 DeInitializePadArray();
77 if(fNumberOfPadsInRow){
78 delete [] fNumberOfPadsInRow;
79 fNumberOfPadsInRow=NULL;
82 delete [] fFirstPadHigh;
95 // Public functions to implement AliHLTComponent's interface.
96 // These functions are required for the registration process
98 const char* AliHLTTPCHWCFDataReverterComponent::GetComponentID()
100 // see header file for class documentation
101 return "TPCHWCFDataReverter";
104 void AliHLTTPCHWCFDataReverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
106 // see header file for class documentation
108 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
111 AliHLTComponentDataType AliHLTTPCHWCFDataReverterComponent::GetOutputDataType()
113 // see header file for class documentation
114 return kAliHLTDataTypeDDLRaw;
117 int AliHLTTPCHWCFDataReverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
119 // see header file for class documentation
121 tgtList.push_back(kAliHLTDataTypeDDLRaw);
122 return tgtList.size();
125 void AliHLTTPCHWCFDataReverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
127 // see header file for class documentation
132 AliHLTComponent* AliHLTTPCHWCFDataReverterComponent::Spawn()
134 // see header file for class documentation
135 return new AliHLTTPCHWCFDataReverterComponent();
138 int AliHLTTPCHWCFDataReverterComponent::DoInit( int argc, const char** argv )
140 // see header file for class documentation
147 // -- number of timebins
148 if ( !strcmp( argv[i], "-timebins" )) {
149 fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
150 AliHLTTPCTransform::SetNTimeBins(fNTimeBins);
152 HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
158 // -- number of timebins
159 if ( !strcmp( argv[i], "-interleave-off" )) {
160 fInterleave = kFALSE;
165 HLTError("HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
170 HLTDebug("using AliHLTTPCDigitReaderDecoder");
171 fDigitReader = new AliHLTTPCDigitReaderDecoder();
176 int AliHLTTPCHWCFDataReverterComponent::DoDeinit()
178 // see header file for class documentation
182 Int_t AliHLTTPCHWCFDataReverterComponent::DeInitializePadArray()
184 // see header file for class documentation
185 if(fVectorInitialized){
186 for(Int_t i=0;i<fNumberOfRows;i++){
187 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
188 delete fRowPadVector[i][j];
189 fRowPadVector[i][j]=NULL;
191 fRowPadVector[i].clear();
193 fRowPadVector.clear();
198 void AliHLTTPCHWCFDataReverterComponent::InitializePadArray(){
199 // see header file for class documentation
201 HLTFatal("Patch is not set");
205 fFirstRow = AliHLTTPCTransform::GetFirstRow(fCurrentPatch);
206 fLastRow = AliHLTTPCTransform::GetLastRow(fCurrentPatch);
208 fNumberOfRows=fLastRow-fFirstRow+1;
209 fNumberOfPadsInRow= new Int_t[fNumberOfRows];
210 fFirstPadHigh= new Int_t[fNumberOfRows];
212 memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
213 memset( fFirstPadHigh, 0, sizeof(Int_t)*(fNumberOfRows));
215 for(Int_t i=0;i<fNumberOfRows;i++){
216 fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
217 AliHLTTPCPadVector tmpRow;
218 for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
219 AliHLTTPCPad *tmpPad = new AliHLTTPCPad();
220 if(fFirstPadHigh[i] == 0){
221 if(fMapping->GetHwAddress(i,j) > 2047){
226 tmpPad->SetDataToDefault();
227 tmpRow.push_back(tmpPad);
229 fRowPadVector.push_back(tmpRow);
231 fVectorInitialized=kTRUE;
235 int AliHLTTPCHWCFDataReverterComponent::DoEvent( const AliHLTComponentEventData& evtData,
236 const AliHLTComponentBlockData* blocks,
237 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
238 AliHLTUInt32_t& size,
239 vector<AliHLTComponentBlockData>& outputBlocks )
241 // see header file for class documentation
243 if (!fDigitReader) return -ENODEV;
245 AliHLTUInt32_t capacity=size;
247 if (!IsDataEvent()) return 0;
249 // == init iter (pointer to datablock)
250 const AliHLTComponentBlockData* iter = NULL;
254 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
258 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
259 evtData.fEventID, evtData.fEventID,
260 DataType2Text( iter->fDataType).c_str(),
261 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
263 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)){
267 if (iter->fSize<=sizeof(AliRawDataHeader)) {
268 // forward empty DDLs
269 outputBlocks.push_back(*iter);
273 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
274 UInt_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
276 if(fDigitReader->InitBlock(iter->fPtr,iter->fSize,patch,slice)<0){
277 HLTWarning("Decoder failed to initialize, event aborted.");
281 fMapping = new AliHLTTPCMapping(patch);
283 if(!fVectorInitialized){
285 InitializePadArray();
288 //Here the reading of the data and the zerosuppression takes place
289 while(fDigitReader->NextChannel()){//Pad
291 Int_t row=fDigitReader->GetRow();
292 Int_t pad=fDigitReader->GetPad();
294 if(row >= fNumberOfRows || row < 0){
297 else if(pad >= fNumberOfPadsInRow[row] || pad < 0){
301 AliHLTTPCPad *tmpPad = fRowPadVector[row][pad];
303 tmpPad->SetDataToDefault();
306 //reading data to pad
307 while(fDigitReader->NextBunch()){
308 const UInt_t *bunchData= fDigitReader->GetSignals();
309 Int_t time=fDigitReader->GetTime();
310 for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
311 if(bunchData[i]>0){// disregarding 0 data.
312 if(time+i >= 0 && time+i < AliHLTTPCTransform::GetNTimeBins()){
314 tmpPad->SetDataSignal(time+i,bunchData[i]);
322 if( iter->fSize > sizeof(AliRawDataHeader )){
324 AliHLTAltroEncoder *altroEncoder = new AliHLTAltroEncoder;
325 altroEncoder->SetUse32BitFormat(kTRUE);
327 if (patch>1) ddlno+=72+4*slice+(patch-2);
328 else ddlno+=2*slice+patch;
329 altroEncoder->SetDDLid(ddlno);
330 altroEncoder->SetSlice(slice);
331 altroEncoder->SetPartition(patch);
333 altroEncoder->SetBuffer(outputPtr,capacity); //tests if one overwrite the buffer is done in the encoder
335 // set CDH from the beginning of buffer
336 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
338 UChar_t *RCUTrailer=NULL;
339 Int_t RCUTrailerSize=fDigitReader->GetRCUTrailerSize();
340 if (RCUTrailerSize<=0 || !fDigitReader->GetRCUTrailerData( RCUTrailer )) {
341 if(RCUTrailer==NULL){
342 HLTWarning("can not find RCU trailer for data block %s 0x%08x: skipping data block",
343 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
347 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
349 for(Int_t row = 0; row< fNumberOfRows;row++){
351 if(fInterleave == kFALSE){
352 Int_t currentTime = 0;
354 for(Int_t ipad=0;ipad<fNumberOfPadsInRow[row];ipad++){
355 AliHLTTPCPad * pad = fRowPadVector[row][ipad];
356 if(pad->GetNAddedSignals() > 0){
357 while(pad->GetNextGoodSignal(currentTime, bunchSize)){
358 for(Int_t i=bunchSize-1;i>=0;i--){
359 if (altroEncoder->AddSignal((AliHLTUInt16_t)(pad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
360 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d Charge %d",
361 slice, patch, fMapping->GetHwAddress(row,ipad), row, ipad, currentTime+i, bunchSize,pad->GetDataSignal(currentTime+i));
366 altroEncoder->SetChannel(fMapping->GetHwAddress(row,ipad));
373 Int_t padHigh=fFirstPadHigh[row];
376 Int_t padHighIndex= padHigh;
378 while(padLowIndex < padHigh || padHighIndex < fNumberOfPadsInRow[row]){
379 Int_t currentTime = 0;
381 //add the data from low side
382 if(padLowIndex < padHigh){
383 AliHLTTPCPad * lowPad= fRowPadVector[row][padLowIndex];
384 if(lowPad->GetNAddedSignals()>0){
385 while(lowPad->GetNextGoodSignal(currentTime, bunchSize)){
386 for(Int_t i=bunchSize-1;i>=0;i--){
387 if (altroEncoder->AddSignal((AliHLTUInt16_t)(lowPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
388 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
389 slice, patch, fMapping->GetHwAddress(row,padLowIndex), row, padLowIndex, currentTime+i, bunchSize);
394 altroEncoder->SetChannel(fMapping->GetHwAddress(row,padLowIndex));
399 //add the data from the high side
400 if(padHighIndex < fNumberOfPadsInRow[row]){
401 AliHLTTPCPad * highPad= fRowPadVector[row][padHighIndex];
402 if(highPad->GetNAddedSignals()>0){
403 while(highPad->GetNextGoodSignal(currentTime, bunchSize)){
404 for(Int_t i=bunchSize-1;i>=0;i--){
405 if (altroEncoder->AddSignal((AliHLTUInt16_t)(highPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
406 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
407 slice, patch, fMapping->GetHwAddress(row,padHighIndex), row, padHighIndex, currentTime+i, bunchSize);
412 altroEncoder->SetChannel(fMapping->GetHwAddress(row,padHighIndex));
421 int sizeOfData=altroEncoder->SetLength();
425 HLTError("data encoding failed");
429 if(sizeOfData>(int)capacity){
430 HLTWarning("Buffer too small too add the altrodata: %d of %d byte(s) already used", sizeOfData, capacity);
435 AliHLTComponentBlockData bd;
438 bd.fSize = sizeOfData;
439 bd.fDataType = kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC;
440 bd.fSpecification = iter->fSpecification;
441 outputBlocks.push_back( bd );
445 fDigitReader->Reset();
449 fDigitReader->Reset();
452 HLTDebug("Total size of output is: %d ",size);