LCOV - code coverage report
Current view: top level - HLT/TPCLib/HWCFemulator - AliHLTTPCHWCFEmulator.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 101 10.9 %
Date: 2016-06-14 17:26:59 Functions: 4 13 30.8 %

          Line data    Source code
       1             : // $Id$
       2             : //****************************************************************************
       3             : //* This file is property of and copyright by the ALICE HLT Project          * 
       4             : //* ALICE Experiment at CERN, All rights reserved.                           *
       5             : //*                                                                          *
       6             : //* Primary Authors: Sergey Gorbunov, Torsten Alt                            *
       7             : //* Developers:      Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> *
       8             : //*                  Torsten Alt <talt@cern.ch>                              *
       9             : //*                  for The ALICE HLT Project.                              *
      10             : //*                                                                          *
      11             : //* Permission to use, copy, modify and distribute this software and its     *
      12             : //* documentation strictly for non-commercial purposes is hereby granted     *
      13             : //* without fee, provided that the above copyright notice appears in all     *
      14             : //* copies and that both the copyright notice and this permission notice     *
      15             : //* appear in the supporting documentation. The authors make no claims       *
      16             : //* about the suitability of this software for any purpose. It is            *
      17             : //* provided "as is" without express or implied warranty.                    *
      18             : //****************************************************************************
      19             : 
      20             : //  @file   AliHLTTPCHWCFEmulator.cxx
      21             : //  @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
      22             : //  @author Torsten Alt <talt@cern.ch> 
      23             : //  @brief  FPGA ClusterFinder Emulator for TPC
      24             : //  @note
      25             : 
      26             : 
      27             : #include "AliHLTTPCHWCFDataTypes.h"
      28             : #include "AliHLTTPCHWCFEmulator.h"
      29             : #include "AliHLTTPCClusterMCData.h"
      30             : #include "AliHLTTPCHWCFData.h"
      31             : 
      32             : #include <iostream>
      33             : 
      34             : #if __GNUC__ >= 3
      35             : using namespace std;
      36             : #endif
      37             : 
      38             : 
      39             : AliHLTTPCHWCFEmulator::AliHLTTPCHWCFEmulator()
      40             :   :
      41           3 :   fDebug(0),
      42           3 :   fkMapping(0),
      43           3 :   fChannelExtractor(),
      44           3 :   fPeakFinderUnit(),
      45           3 :   fChannelProcessor(),
      46           3 :   fChannelMerger(),
      47           3 :   fDivisionUnit()
      48          12 : {
      49             :   //constructor 
      50           6 : }
      51             : 
      52             : AliHLTTPCHWCFEmulator::~AliHLTTPCHWCFEmulator()
      53          12 : {   
      54             :   //destructor
      55           6 : }
      56             : 
      57             : AliHLTTPCHWCFEmulator::AliHLTTPCHWCFEmulator(const AliHLTTPCHWCFEmulator&)
      58             :   :
      59           0 :   fDebug(0),
      60           0 :   fkMapping(0),
      61           0 :   fChannelExtractor(),
      62           0 :   fPeakFinderUnit(),
      63           0 :   fChannelProcessor(),
      64           0 :   fChannelMerger(),
      65           0 :   fDivisionUnit()
      66           0 : {
      67             :   // dummy
      68           0 : }
      69             : 
      70             : AliHLTTPCHWCFEmulator& AliHLTTPCHWCFEmulator::operator=(const AliHLTTPCHWCFEmulator&)
      71             : {
      72             :   // dummy
      73           0 :   return *this;
      74             : }
      75             : 
      76             : void AliHLTTPCHWCFEmulator::Init( const AliHLTUInt32_t *mapping, AliHLTUInt32_t config1, AliHLTUInt32_t config2 )
      77             : {
      78             :   // Initialisation
      79           0 :   fkMapping = mapping;
      80             :   
      81           0 :   fPeakFinderUnit.SetChargeFluctuation( (config2>>4) & 0xF );
      82             : 
      83           0 :   fChannelProcessor.SetSingleSeqLimit( (config1) & 0xFF );
      84           0 :   fChannelProcessor.SetDeconvolutionTime( (config1>>24) & 0x1 );
      85           0 :   fChannelProcessor.SetUseTimeBinWindow( (config2>>8) & 0x1 );
      86             : 
      87             :  
      88           0 :   fChannelMerger.SetByPassMerger( (config1>>27) & 0x1 );
      89           0 :   fChannelMerger.SetDeconvolution( (config1>>25) & 0x1 );
      90           0 :   fChannelMerger.SetMatchDistance( (config2) & 0xF );
      91           0 :   fChannelMerger.SetMatchTimeFollow( (config2>>9) & 0x1 );
      92             : 
      93           0 :   fDivisionUnit.SetClusterLowerLimit( (config1>>8) & 0xFFFF );
      94           0 :   fDivisionUnit.SetSinglePadSuppression( (config1>>26) & 0x1 );
      95             : 
      96           0 :   fPeakFinderUnit.SetDebugLevel(fDebug);
      97           0 :   fChannelProcessor.SetDebugLevel(fDebug);
      98           0 :   fChannelMerger.SetDebugLevel(fDebug);
      99           0 :   fDivisionUnit.SetDebugLevel(fDebug);
     100           0 : }
     101             : 
     102             :  
     103             : int AliHLTTPCHWCFEmulator::FindClusters( const AliHLTUInt32_t *rawEvent,
     104             :                                          AliHLTUInt32_t rawEventSize32,
     105             :                                          AliHLTUInt32_t *output,
     106             :                                          AliHLTUInt32_t &outputSize32,
     107             :                                          const AliHLTTPCClusterMCLabel *mcLabels,
     108             :                                          AliHLTUInt32_t nMCLabels,
     109             :                                          AliHLTTPCClusterMCData *outputMC
     110             :                                          )
     111             : {  
     112             :   // Loops over all rows finding the clusters 
     113             : 
     114           0 :   AliHLTUInt32_t maxOutputSize32 = outputSize32;
     115           0 :   outputSize32 = 0;
     116           0 :   if( outputMC ) outputMC->fCount = 0;   
     117             :   AliHLTUInt32_t maxNMCLabels = nMCLabels;
     118           0 :   if( !rawEvent ) return -1;    
     119             : 
     120             :   // Initialise 
     121             : 
     122             :   int ret = 0;
     123             :   
     124           0 :   fChannelExtractor.Init( fkMapping, mcLabels, 3*rawEventSize32 );
     125           0 :   fPeakFinderUnit.Init();
     126           0 :   fChannelProcessor.Init();
     127           0 :   fChannelMerger.Init();
     128           0 :   fDivisionUnit.Init();
     129             : 
     130             :   // Read the data, word by word 
     131             :   
     132           0 :   for( AliHLTUInt32_t  iWord=0; iWord<=rawEventSize32; iWord++ ){
     133             : 
     134             :     const AliHLTTPCHWCFBunch *bunch1=0;
     135             :     const AliHLTTPCHWCFBunch *bunch2=0;
     136             :     const AliHLTTPCHWCFClusterFragment *fragment=0;
     137             :     const AliHLTTPCHWCFClusterFragment *candidate=0;
     138             :     const AliHLTTPCHWCFCluster *cluster = 0;
     139             :     
     140           0 :     if( iWord<rawEventSize32 ) fChannelExtractor.InputStream(ReadBigEndian(rawEvent[iWord]));
     141           0 :     else fChannelExtractor.InputEndOfData();
     142             : 
     143           0 :     while( (bunch1 = fChannelExtractor.OutputStream()) ){ 
     144           0 :       fPeakFinderUnit.InputStream(bunch1);
     145           0 :       while( (bunch2 = fPeakFinderUnit.OutputStream() )){       
     146           0 :         fChannelProcessor.InputStream(bunch2);
     147           0 :         while( (fragment = fChannelProcessor.OutputStream() )){ 
     148           0 :           fChannelMerger.InputStream( fragment );
     149           0 :           while( (candidate = fChannelMerger.OutputStream()) ){           
     150           0 :             fDivisionUnit.InputStream(candidate);
     151           0 :             while( (cluster = fDivisionUnit.OutputStream()) ){      
     152           0 :               if( cluster->fFlag==1 ){
     153           0 :                 if( outputSize32+AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize > maxOutputSize32 ){ // No space in the output buffer
     154             :                   ret = -2;
     155           0 :                   break;
     156             :                 }             
     157           0 :                 AliHLTUInt32_t *co = &output[outputSize32];
     158             :                 int i=0;
     159           0 :                 co[i++] = WriteBigEndian(cluster->fRowQ);
     160           0 :                 co[i++] = WriteBigEndian(cluster->fQ);
     161           0 :                 co[i++] = cluster->fP;
     162           0 :                 co[i++] = cluster->fT;
     163           0 :                 co[i++] = cluster->fP2;
     164           0 :                 co[i++] = cluster->fT2;
     165           0 :                 outputSize32+=AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize;
     166           0 :                 if( mcLabels && outputMC && outputMC->fCount < maxNMCLabels){
     167           0 :                   outputMC->fLabels[outputMC->fCount++] = cluster->fMC;
     168           0 :                 }
     169           0 :               }
     170           0 :               else if( cluster->fFlag==2 ){
     171           0 :                 if( outputSize32+1 > maxOutputSize32 ){ // No space in the output buffer
     172             :                   ret = -2;
     173           0 :                   break;
     174             :                 }
     175           0 :                 output[outputSize32++] = cluster->fRowQ;
     176           0 :               }
     177             :             }
     178             :           }
     179             :         }
     180             :       }
     181             :     }
     182             :   }
     183             :   return ret;
     184           0 : }
     185             : 
     186             : AliHLTUInt32_t AliHLTTPCHWCFEmulator::ReadBigEndian ( AliHLTUInt32_t word )
     187             : {  
     188             :   // read the word written in big endian format (lowest byte first)
     189             : 
     190             :   const AliHLTUInt8_t *bytes = reinterpret_cast<const AliHLTUInt8_t *>( &word );
     191           0 :   AliHLTUInt32_t i[4] = {bytes[0],bytes[1],bytes[2],bytes[3]};
     192             : 
     193           0 :   return (i[3]<<24) | (i[2]<<16) | (i[1]<<8) | i[0];
     194             : }
     195             : 
     196             : AliHLTUInt32_t AliHLTTPCHWCFEmulator::WriteBigEndian ( AliHLTUInt32_t word )
     197             : {
     198             :   // write the word in big endian format (least byte first)
     199             :   
     200             :   AliHLTUInt32_t ret = 0;
     201             :   AliHLTUInt8_t *bytes = reinterpret_cast<AliHLTUInt8_t *>( &ret );
     202           0 :   bytes[0] = (word      ) & 0xFF;
     203           0 :   bytes[1] = (word >>  8) & 0xFF;
     204           0 :   bytes[2] = (word >> 16) & 0xFF;
     205           0 :   bytes[3] = (word >> 24) & 0xFF;
     206           0 :   return ret;
     207           0 : }
     208             : 
     209             : void AliHLTTPCHWCFEmulator::CreateConfiguration
     210             : (
     211             :  bool doDeconvTime, bool doDeconvPad, bool doFlowControl, 
     212             :  bool doSinglePadSuppression, bool bypassMerger, 
     213             :  AliHLTUInt32_t clusterLowerLimit, AliHLTUInt32_t singleSeqLimit, 
     214             :  AliHLTUInt32_t mergerDistance, bool useTimeBinWindow, AliHLTUInt32_t chargeFluctuation, bool useTimeFollow,
     215             :  AliHLTUInt32_t &configWord1, AliHLTUInt32_t &configWord2 
     216             :  )
     217             : {
     218             :   // static method to create configuration word 
     219             : 
     220           0 :   configWord1 = 0;
     221           0 :   configWord2 = 0;
     222             : 
     223           0 :   configWord1 |= ( (AliHLTUInt32_t)doFlowControl & 0x1 ) << 29;
     224           0 :   configWord1 |= ( (AliHLTUInt32_t)bypassMerger & 0x1 ) << 27;
     225           0 :   configWord1 |= ( (AliHLTUInt32_t)doSinglePadSuppression & 0x1 ) << 26;
     226           0 :   configWord1 |= ( (AliHLTUInt32_t)doDeconvPad & 0x1 ) << 25;
     227           0 :   configWord1 |= ( (AliHLTUInt32_t)doDeconvTime & 0x1 ) << 24;
     228           0 :   configWord1 |= ( (AliHLTUInt32_t)clusterLowerLimit & 0xFFFF )<<8;
     229           0 :   configWord1 |= ( (AliHLTUInt32_t)singleSeqLimit & 0xFF );
     230             : 
     231           0 :   configWord2 |= ( (AliHLTUInt32_t)mergerDistance & 0xF );
     232           0 :   configWord2 |= ( (AliHLTUInt32_t)chargeFluctuation  & 0xF )<<4;
     233           0 :   configWord2 |= ( (AliHLTUInt32_t)useTimeBinWindow  & 0x1 )<<8;
     234           0 :   configWord2 |= ( (AliHLTUInt32_t)useTimeFollow  & 0x1 )<<9;
     235           0 : }

Generated by: LCOV version 1.11