LCOV - code coverage report
Current view: top level - HLT/TPCLib/HWCFemulator - AliHLTTPCHWCFEmulatorComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 346 7.2 %
Date: 2016-06-14 17:26:59 Functions: 6 24 25.0 %

          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   AliHLTTPCHWCFEmulatorComponent.cxx
      21             : //  @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
      22             : //  @author Torsten Alt <talt@cern.ch> 
      23             : //  @brief  HLT Component interface for for FPGA ClusterFinder Emulator for TPC
      24             : //  @brief  ( see AliHLTTPCHWCFEmulator class )
      25             : //  @note
      26             : 
      27             : 
      28             : #include "AliHLTTPCHWCFEmulatorComponent.h"
      29             : 
      30             : #include "AliHLTTPCDefinitions.h"
      31             : #include "AliHLTTPCHWCFDataTypes.h"
      32             : #include "AliHLTTPCClusterMCData.h"
      33             : #include "AliHLTTPCHWCFData.h"
      34             : 
      35             : #include "AliGRPObject.h"
      36             : #include "AliCDBEntry.h"
      37             : #include "AliCDBManager.h"
      38             : #include "AliHLTCDHWrapper.h"
      39             : #include <cstdlib>
      40             : #include <cerrno>
      41             : #include <memory>
      42             : #include "TString.h"
      43             : #include "TObjString.h"
      44             : #include "TObjArray.h"
      45             : 
      46             : 
      47             : #include <sys/time.h>
      48             : #include "TFile.h"
      49             : 
      50             : using namespace std;
      51             : 
      52             : AliHLTTPCHWCFEmulatorComponent::AliHLTTPCHWCFEmulatorComponent()
      53             :   :
      54           3 :   AliHLTProcessor(),
      55           3 :   fDoDeconvTime(0),
      56           3 :   fDoDeconvPad(0),
      57           3 :   fDoMC(0),
      58           3 :   fDoFlowControl(0),
      59           3 :   fDoSinglePadSuppression(0),
      60           3 :   fBypassMerger(0),
      61           3 :   fClusterLowerLimit(0),
      62           3 :   fSingleSeqLimit(0),
      63           3 :   fMergerDistance(0),
      64           3 :   fUseTimeBinWindow(0),
      65           3 :   fUseTimeFollow(0),
      66           3 :   fChargeFluctuation(0),
      67           3 :   fTagDeconvolutedClusters(0),
      68           3 :   fProcessingRCU2Data(0),
      69           3 :   fNoiseSuppression(0),
      70           3 :   fDebug(0),
      71           3 :   fCFSupport(),
      72           3 :   fCFEmulator(),
      73           3 :   fBenchmark("TPCHWClusterFinderEmulator")
      74          15 : {
      75             :   // see header file for class documentation
      76             :   // or
      77             :   // refer to README to build package
      78             :   // or
      79             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      80           6 : }
      81             : 
      82             : 
      83             : AliHLTTPCHWCFEmulatorComponent::AliHLTTPCHWCFEmulatorComponent(const AliHLTTPCHWCFEmulatorComponent&)
      84             :   :
      85           0 :   AliHLTProcessor(),
      86           0 :   fDoDeconvTime(0),
      87           0 :   fDoDeconvPad(0),
      88           0 :   fDoMC(0),
      89           0 :   fDoFlowControl(0),
      90           0 :   fDoSinglePadSuppression(0),
      91           0 :   fBypassMerger(0),
      92           0 :   fClusterLowerLimit(0),
      93           0 :   fSingleSeqLimit(0),
      94           0 :   fMergerDistance(0),
      95           0 :   fUseTimeBinWindow(0),
      96           0 :   fUseTimeFollow(0),
      97           0 :   fChargeFluctuation(0),
      98           0 :   fTagDeconvolutedClusters(0),
      99           0 :   fProcessingRCU2Data(0),
     100           0 :   fDebug(0),
     101           0 :   fCFSupport(),
     102           0 :   fCFEmulator(),
     103           0 :   fBenchmark("TPCHWClusterFinderEmulator")
     104           0 : {
     105             :   // dummy
     106           0 : }
     107             : 
     108             : AliHLTTPCHWCFEmulatorComponent& AliHLTTPCHWCFEmulatorComponent::operator=(const AliHLTTPCHWCFEmulatorComponent&)
     109             : {
     110             :   // dummy
     111           0 :   return *this;
     112             : }
     113             : 
     114             : AliHLTTPCHWCFEmulatorComponent::~AliHLTTPCHWCFEmulatorComponent()
     115          18 : {
     116             :   // see header file for class documentation
     117           9 : }
     118             : 
     119             : // Public functions to implement AliHLTComponent's interface.
     120             : // These functions are required for the registration process
     121             : 
     122             : const char* AliHLTTPCHWCFEmulatorComponent::GetComponentID()
     123             : {
     124             :   // see header file for class documentation
     125         438 :   return "TPCHWClusterFinderEmulator";
     126             : }
     127             : 
     128             : void AliHLTTPCHWCFEmulatorComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
     129             : {
     130             :   // see header file for class documentation
     131           0 :   list.clear();
     132           0 :   list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );        
     133           0 :   list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
     134           0 :   list.push_back( AliHLTTPCDefinitions::RawClustersDataType() | kAliHLTDataOriginTPC );
     135           0 :   list.push_back( AliHLTTPCDefinitions::RawClustersDescriptorDataType() | kAliHLTDataOriginTPC );
     136           0 : }
     137             : 
     138             : AliHLTComponentDataType AliHLTTPCHWCFEmulatorComponent::GetOutputDataType()
     139             : {
     140             :   // see header file for class documentation
     141           0 :   return kAliHLTMultipleDataType;
     142             : }
     143             : 
     144             : int AliHLTTPCHWCFEmulatorComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
     145             : {
     146             :   // see header file for class documentation
     147           0 :   tgtList.clear();
     148           0 :   tgtList.push_back(AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC );
     149           0 :   tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
     150           0 :   tgtList.push_back( AliHLTTPCDefinitions::RawClustersDataType() | kAliHLTDataOriginTPC );
     151           0 :   tgtList.push_back( AliHLTTPCDefinitions::RawClustersDescriptorDataType() | kAliHLTDataOriginTPC );
     152           0 :   return tgtList.size();
     153             : }
     154             : 
     155             : 
     156             : void AliHLTTPCHWCFEmulatorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
     157             : {
     158             :   // see header file for class documentation
     159             :   // XXX TODO: Find more realistic values.  
     160           0 :   constBase = 0;
     161           0 :   inputMultiplier = (6 * 0.7);
     162           0 : }
     163             : 
     164             : 
     165             : AliHLTComponent* AliHLTTPCHWCFEmulatorComponent::Spawn()
     166             : {
     167             :   // see header file for class documentation
     168           0 :   return new AliHLTTPCHWCFEmulatorComponent();
     169           0 : }
     170             : 
     171             : void AliHLTTPCHWCFEmulatorComponent::GetOCDBObjectDescription( TMap* const targetMap){
     172             : // Get a list of OCDB object description needed for the particular component
     173             :   
     174           0 :   if (!targetMap) return;
     175             :   
     176             :   // OCDB entries for component arguments
     177           0 :   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterFinder"), new TObjString("component arguments, empty at the moment"));
     178           0 : }
     179             : 
     180             : 
     181             : int AliHLTTPCHWCFEmulatorComponent::DoInit( int argc, const char** argv )
     182             : {
     183             :   // see header file for class documentation
     184             : 
     185           0 :   TString arguments = "";
     186           0 :   for ( int i = 0; i < argc; i++ ) {
     187           0 :     if ( !arguments.IsNull() ) arguments += " ";
     188           0 :     arguments += argv[i];
     189             :   }
     190             : 
     191           0 :   return Configure( NULL, NULL, arguments.Data()  );
     192           0 : }
     193             : 
     194             : int AliHLTTPCHWCFEmulatorComponent::Reconfigure( const char* cdbEntry, const char* chainId )
     195             : {
     196             :   // Reconfigure the component from OCDB
     197             : 
     198           0 :   return Configure( cdbEntry, chainId, NULL );
     199             : }
     200             : 
     201             : int AliHLTTPCHWCFEmulatorComponent::ScanConfigurationArgument(int argc, const char** argv)
     202             : {
     203             :   // see header file for class documentation
     204           0 :   TString arguments = "";
     205           0 :   for ( int i = 0; i < argc; i++ ) {
     206           0 :     if ( !arguments.IsNull() ) arguments += " ";
     207           0 :     arguments += argv[i];
     208             :   }
     209           0 :   return ReadConfigurationString(arguments);
     210           0 : }
     211             : 
     212             : 
     213             : 
     214             : void AliHLTTPCHWCFEmulatorComponent::SetDefaultConfiguration()
     215             : {
     216             :   // Set default configuration for the FPGA ClusterFinder Emulator component
     217             :   // Some parameters can be later overwritten from the OCDB
     218             : 
     219           0 :   fDoDeconvTime = 1;
     220           0 :   fDoDeconvPad = 1;
     221           0 :   fDoMC = 0;
     222           0 :   fDoFlowControl = 0;
     223           0 :   fDoSinglePadSuppression = 0;
     224           0 :   fBypassMerger = 0;
     225           0 :   fClusterLowerLimit = 10;
     226           0 :   fSingleSeqLimit = 0;
     227           0 :   fMergerDistance = 4;
     228           0 :   fUseTimeBinWindow = 1;
     229           0 :   fUseTimeFollow = 1;
     230           0 :   fChargeFluctuation = 0;
     231           0 :   fTagDeconvolutedClusters = 0;
     232           0 :   fProcessingRCU2Data = 0;
     233           0 :   fDebug = 0;
     234           0 :   fBenchmark.Reset();
     235           0 :   fBenchmark.SetTimer(0,"total");
     236           0 :   fBenchmark.SetTimer(1,"reco");    
     237           0 : }
     238             : 
     239             : int AliHLTTPCHWCFEmulatorComponent::ReadConfigurationString(  const char* arguments )
     240             : {
     241             :   // Set configuration parameters for the FPGA ClusterFinder Emulator component
     242             :   // from the string
     243             : 
     244             :   int iResult = 0;
     245           0 :   if ( !arguments ) return iResult;
     246             :   //cout<<"["<<arguments<<"]"<<endl;
     247           0 :   TString allArgs = arguments;
     248           0 :   TString argument;
     249             :   int bMissingParam = 0;
     250             : 
     251           0 :   TObjArray* pTokens = allArgs.Tokenize( " " );
     252             : 
     253           0 :   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
     254             : 
     255           0 :   for ( int i = 0; i < nArgs; i++ ) {
     256           0 :     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
     257           0 :     if ( argument.IsNull() ) continue;
     258             : 
     259           0 :     if ( argument.CompareTo( "-deconvolute-time" ) == 0 ) {
     260           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     261           0 :       fDoDeconvTime  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     262           0 :       fUseTimeBinWindow = fDoDeconvTime;
     263           0 :       HLTInfo( "Time deconvolution and using of TimeBin window are set to: %d", fDoDeconvTime );
     264             :       continue;
     265             :     }
     266             : 
     267           0 :     if ( argument.CompareTo( "-deconvolute-pad" ) == 0 ) {
     268           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     269           0 :       fDoDeconvPad  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     270           0 :       HLTInfo( "Pad deconvolution is set to: %d", fDoDeconvPad );
     271             :       continue;
     272             :     }
     273             : 
     274           0 :     if ( argument.CompareTo( "-deconvolute" ) == 0 ) {
     275           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     276           0 :       fDoDeconvTime  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     277           0 :       fUseTimeBinWindow = fDoDeconvTime;
     278           0 :       fDoDeconvPad  = fDoDeconvTime;
     279           0 :       HLTInfo( "Time and pad deconvolution and using of TimeBin window are set to: %d", fDoDeconvPad );
     280             :       continue;
     281             :     }
     282             :  
     283           0 :     if ( argument.CompareTo( "-do-mc" ) == 0 ) {
     284           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     285           0 :       fDoMC  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     286           0 :       HLTInfo( "MC processing is set to: %d", fDoMC );
     287             :       continue;
     288             :     }
     289             : 
     290           0 :     if ( argument.CompareTo( "-flow-control" ) == 0 ) {
     291           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     292           0 :       fDoFlowControl  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     293           0 :       HLTInfo( "Flow control is set to: %d", fDoFlowControl );
     294             :       continue;
     295             :     }
     296             : 
     297           0 :     if ( argument.CompareTo( "-single-pad-suppression" ) == 0 ) {
     298           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     299           0 :       fDoSinglePadSuppression  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     300           0 :       HLTInfo( "Single pad suppression is set to: %d", fDoSinglePadSuppression );
     301             :       continue;
     302             :     }
     303             :     
     304           0 :     if ( argument.CompareTo( "-bypass-merger" ) == 0 ) {
     305           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     306           0 :       fBypassMerger  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     307           0 :       HLTInfo( "Bypassing merger is set to: %d", fBypassMerger );
     308             :       continue;
     309             :     }
     310             : 
     311           0 :     if ( argument.CompareTo( "-cluster-lower-limit" ) == 0 ) {
     312           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     313           0 :       fClusterLowerLimit  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     314           0 :       HLTInfo( "Cluster lower limit is set to: %d", fClusterLowerLimit );
     315             :       continue;
     316             :     }
     317             : 
     318           0 :     if ( argument.CompareTo( "-single-sequence-limit" ) == 0 ) {
     319           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     320           0 :       fSingleSeqLimit  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     321           0 :       HLTInfo( "Single sequence limit is set to: %d", fSingleSeqLimit );
     322             :       continue;
     323             :     }
     324             :     
     325           0 :     if ( argument.CompareTo( "-merger-distance" ) == 0 ) {
     326           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     327           0 :       fMergerDistance  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     328           0 :       HLTInfo( "Merger distance is set to: %d", fMergerDistance );
     329             :       continue;
     330             :     }
     331             :  
     332           0 :     if ( argument.CompareTo( "-use-timebin-window" ) == 0 ) {
     333           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     334           0 :       fUseTimeBinWindow  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     335           0 :       fDoDeconvTime = fUseTimeBinWindow;
     336           0 :       HLTInfo( "Using TimeBin window and Time deconvolution are set to: %d", fUseTimeBinWindow );
     337             :       continue;
     338             :     }
     339             :    
     340           0 :     if ( argument.CompareTo( "-charge-fluctuation" ) == 0 ) {
     341           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     342           0 :       fChargeFluctuation  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     343           0 :       HLTInfo( "Charge fluctuation is set to: %d", fChargeFluctuation );
     344             :       continue;
     345             :     }
     346             :     
     347           0 :     if ( argument.CompareTo( "-noise-suppression" ) == 0 ) {
     348           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     349           0 :       fNoiseSuppression  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     350           0 :       HLTInfo( "Noise Suppression is set to: %d", fNoiseSuppression );
     351             :       continue;
     352             :     }
     353             : 
     354           0 :     if ( argument.CompareTo( "-use-time-follow" ) == 0 ) {
     355           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     356           0 :       fUseTimeFollow  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     357           0 :       HLTInfo( "Use of time follow algorithm is set to: %d", fUseTimeFollow );
     358             :       continue;
     359             :     }
     360             :    
     361           0 :     if ( argument.CompareTo( "-debug-level" ) == 0 ) {
     362           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     363           0 :       fDebug  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     364           0 :       HLTInfo( "Debug level is set to: %d", fDebug );
     365             :       continue;
     366             :     }
     367             : 
     368           0 :     if ( argument.CompareTo( "-tag-deconvoluted-clusters" ) == 0 ) {
     369           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     370           0 :       fTagDeconvolutedClusters  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     371           0 :       HLTInfo( "Tag Deconvoluted Clusters is set to: %d", fTagDeconvolutedClusters );
     372             :       continue;
     373             :     }
     374             :  
     375           0 :     if ( argument.CompareTo( "-rcu2-data" ) == 0 ) {
     376           0 :       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
     377           0 :       fProcessingRCU2Data  = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
     378           0 :       HLTInfo( "Processing RCU2 data flag is set to: %d", fProcessingRCU2Data );
     379             :       continue;
     380             :     }
     381             :    
     382           0 :     HLTError( "Unknown option \"%s\"", argument.Data() );
     383             :     iResult = -EINVAL;
     384           0 :   }
     385           0 :   delete pTokens;
     386             : 
     387           0 :   if ( bMissingParam ) {
     388           0 :     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
     389             :     iResult = -EINVAL;
     390           0 :   }
     391             : 
     392             :   return iResult;
     393           0 : }
     394             : 
     395             : 
     396             : int AliHLTTPCHWCFEmulatorComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
     397             : {
     398             :   // Read configuration from OCDB
     399             : 
     400             :   const char* defaultNotify = "";
     401             : 
     402           0 :   if ( !cdbEntry ){
     403             :     cdbEntry = "HLT/ConfigTPC/TPCHWClusterFinder";
     404             :     defaultNotify = " (default)";
     405             :     chainId = 0;
     406           0 :   }
     407             : 
     408           0 :   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
     409           0 :   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
     410             :   
     411           0 :   if ( !pEntry ) {
     412           0 :     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
     413           0 :     return -EINVAL;
     414             :   }
     415             : 
     416           0 :   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
     417             : 
     418           0 :   if ( !pString ) {
     419           0 :     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
     420           0 :     return -EINVAL;
     421             :   }
     422             : 
     423           0 :   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
     424             : 
     425           0 :   return  ReadConfigurationString( pString->GetString().Data() );
     426           0 : }
     427             : 
     428             : 
     429             : int AliHLTTPCHWCFEmulatorComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
     430             : {
     431             :   // Configure the component
     432             :   // There are few levels of configuration,
     433             :   // parameters which are set on one step can be overwritten on the next step
     434             : 
     435             :   //* read hard-coded values
     436             : 
     437           0 :   SetDefaultConfiguration();
     438             : 
     439             :   //* read the default CDB entry
     440             : 
     441           0 :   int iResult1 = ReadCDBEntry( NULL, chainId );
     442             : 
     443             :   //* read the actual CDB entry if required
     444             : 
     445           0 :   int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
     446             : 
     447             :   //* read extra parameters from input (if they are)
     448             : 
     449             :   int iResult3 = 0;
     450             : 
     451           0 :   if ( commandLine && commandLine[0] != '\0' ) {
     452           0 :     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
     453           0 :     iResult3 = ReadConfigurationString( commandLine );
     454           0 :   }
     455             :   
     456           0 :   if( fDebug>1 ) fCFEmulator.SetDebugLevel( fDebug );
     457           0 :   else fCFEmulator.SetDebugLevel(0);
     458             : 
     459           0 :   fCFSupport.UnloadMapping();
     460           0 :   fCFSupport.SetProcessingRCU2Data( fProcessingRCU2Data );
     461             : 
     462           0 :   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
     463             : }
     464             : 
     465             : 
     466             : int AliHLTTPCHWCFEmulatorComponent::DoDeinit()
     467             : {
     468             :   // see header file for class documentation 
     469           0 :   return 0;
     470             : }
     471             : 
     472             : 
     473             : int AliHLTTPCHWCFEmulatorComponent::DoEvent( const AliHLTComponentEventData& evtData, 
     474             :                                                         const AliHLTComponentBlockData* blocks, 
     475             :                                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
     476             :                                                         AliHLTUInt32_t& size, 
     477             :                                                         vector<AliHLTComponentBlockData>& outputBlocks )
     478             : {
     479             :   // see header file for class documentation
     480             : 
     481             :   int iResult=0;
     482           0 :   AliHLTUInt32_t maxSize = size;
     483           0 :   size = 0;
     484             :   
     485           0 :   if(!IsDataEvent()){
     486           0 :     return 0;
     487             :   }
     488             : 
     489           0 :   fBenchmark.StartNewEvent();
     490           0 :   fBenchmark.Start(0);
     491             : 
     492           0 :   AliHLTUInt32_t configWord1=0, configWord2=0; 
     493           0 :   AliHLTTPCHWCFEmulator::CreateConfiguration
     494           0 :     ( fDoDeconvTime, fDoDeconvPad, fDoFlowControl, fDoSinglePadSuppression, fBypassMerger, fClusterLowerLimit, fSingleSeqLimit, fMergerDistance, fUseTimeBinWindow, fChargeFluctuation, fUseTimeFollow, configWord1, configWord2 );
     495             : 
     496             :   AliHLTUInt8_t *outBlock = NULL;
     497             :   AliHLTTPCClusterMCLabel *allocOutMC = NULL;
     498             : 
     499           0 :   for ( unsigned long ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     500             :     {
     501           0 :       const AliHLTComponentBlockData* iter = blocks+ndx;
     502             :       
     503           0 :       fBenchmark.AddInput(iter->fSize);
     504             : 
     505           0 :       if (  iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC) 
     506           0 :             &&  iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
     507             : 
     508           0 :       int slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
     509           0 :       int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
     510             :  
     511             :   
     512           0 :       if (!iter->fPtr) continue;
     513             :  
     514             :       // create input block for the HW cluster finder
     515             : 
     516           0 :       const AliHLTUInt32_t *rawEvent=0;
     517           0 :       const AliHLTTPCClusterMCLabel *mcLabels = 0;
     518           0 :       AliHLTUInt32_t rawEventSize32 = 0;
     519           0 :       AliHLTUInt32_t nMCLabels = 0;
     520             : 
     521           0 :       if( fCFSupport.CreateRawEvent( iter, rawEvent, rawEventSize32, mcLabels, nMCLabels )<0 ) continue; 
     522           0 :       if( !fDoMC ){
     523           0 :         mcLabels = 0;
     524           0 :         nMCLabels = 0;
     525           0 :       }
     526             : 
     527             :       
     528           0 :       AliHLTUInt32_t maxNClusters = rawEventSize32 + 1; // N 32-bit words in input
     529           0 :       AliHLTUInt32_t clustersSize32 = maxNClusters*AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize;
     530             :       AliHLTUInt32_t nOutputMC = maxNClusters;
     531             : 
     532             :       // create or forward the CDH header
     533             : 
     534           0 :       AliRawDataHeaderV3 dummyCDHHeader;
     535             : 
     536           0 :       bool isRawInput = ( iter->fDataType == kAliHLTDataTypeDDLRaw );
     537             : 
     538           0 :       AliHLTCDHWrapper header( isRawInput ?iter->fPtr :&dummyCDHHeader );
     539             : 
     540           0 :       AliHLTUInt32_t headerSize = header.GetHeaderSize();
     541             : 
     542             :       // book memory for the output
     543             : 
     544           0 :       AliHLTUInt32_t outBlockSize = headerSize+clustersSize32*sizeof(AliHLTUInt32_t);
     545             : 
     546           0 :       if( outBlock ) delete[] outBlock;
     547           0 :       if( allocOutMC ) delete[] allocOutMC;      
     548           0 :       outBlock = new AliHLTUInt8_t[outBlockSize];
     549           0 :       allocOutMC = new AliHLTTPCClusterMCLabel[nOutputMC+1];
     550             :  
     551           0 :       if (!outBlock || !allocOutMC) {
     552             :         iResult=-ENOMEM;
     553           0 :         break;
     554             :       } 
     555             : 
     556           0 :       memset(outBlock, 0, outBlockSize*sizeof(AliHLTUInt8_t));
     557           0 :       memset(allocOutMC, 0, (nOutputMC+1)*sizeof(AliHLTTPCClusterMCLabel));
     558           0 :       AliHLTTPCClusterMCData *outMC = reinterpret_cast<AliHLTTPCClusterMCData *>(allocOutMC);
     559             :       
     560             :       // fill CDH header here, since the HW clusterfinder does not receive it
     561           0 :       memcpy(outBlock, header.GetHeader(), headerSize );
     562           0 :       memset(outBlock,0xFF,4);
     563             : 
     564             :       //AliRawDataHeader *cdhHeader = reinterpret_cast<AliRawDataHeader*>(iter->fPtr);
     565             :       //AliRawDataHeader *outCDHHeader = reinterpret_cast<AliRawDataHeader*>(outBlock);
     566             :       //*outCDHHeader = *cdhHeader;
     567             :       //outCDHHeader->fSize = 0xFFFFFFFF;
     568             : 
     569           0 :       AliHLTUInt32_t *outClusters = reinterpret_cast<AliHLTUInt32_t*> (outBlock + headerSize);
     570             :      
     571           0 :       fBenchmark.Start(1);
     572           0 :       fCFEmulator.Init
     573           0 :         ( fCFSupport.GetMapping(slice,patch), configWord1, configWord2 );
     574             : 
     575           0 :       fCFEmulator.SetTagDeconvolutedClusters( fTagDeconvolutedClusters );
     576           0 :       fCFEmulator.SetProcessingRCU2Data( fProcessingRCU2Data );
     577           0 :       fCFEmulator.SetNoiseSuppression( fNoiseSuppression );
     578             : 
     579           0 :       int err = fCFEmulator.FindClusters( rawEvent, rawEventSize32, 
     580             :                                           outClusters, clustersSize32, 
     581           0 :                                           mcLabels, nMCLabels,
     582             :                                           outMC );
     583           0 :       fBenchmark.Stop(1);
     584           0 :       if( err==-1 ){ HLTWarning("NULL input pointer (warning %d)",err);}
     585           0 :       else if( err==-2 ){  HLTWarning("No space left in the output buffer (warning %d)",err); }
     586           0 :       else if( err<0 ){ HLTWarning("HWCF emulator finished with error code %d",err); }
     587           0 :       if( err<0 ){
     588           0 :         continue;
     589             :       }
     590             : 
     591           0 :       if( fDebug ){
     592           0 :         int elsize=AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize;
     593           0 :         printf("\nHWCF Emulator: output clusters for slice%d patch %d:\n",slice,patch);
     594           0 :         for( AliHLTUInt32_t i=0; i<clustersSize32; i+=elsize ){
     595           0 :           AliHLTUInt32_t *c = outClusters+i;
     596           0 :           AliHLTUInt32_t flag = (c[0]>>30);         
     597           0 :           if( flag == 0x3){ //beginning of a cluster
     598           0 :             int padRow  = (c[0]>>24)&0x3f;
     599           0 :             int q  = c[1];
     600           0 :             double p   = *((AliHLTFloat32_t*)&c[2]);
     601           0 :             double t  = *((AliHLTFloat32_t*)&c[3]);
     602           0 :             AliHLTFloat32_t p2 = *((AliHLTFloat32_t*)&c[4]);
     603           0 :             AliHLTFloat32_t t2 = *((AliHLTFloat32_t*)&c[5]);
     604           0 :             printf("N: %3d    R: %3d    C: %4d    P:  %7.4f    T:  %8.4f    DP: %6.4f    DT: %6.4f\n", 
     605           0 :                    i/elsize+1, padRow, q, p, t, sqrt(fabs(p2-p*p)), sqrt(fabs(t2-t*t)));
     606             : 
     607           0 :             if( outMC && outMC->fCount>0 ){
     608           0 :               printf("        MC: (%3d,%6.1f) (%3d,%6.1f) (%3d,%6.1f)\n",
     609           0 :                      outMC->fLabels[i/elsize].fClusterID[0].fMCID,outMC->fLabels[i/elsize].fClusterID[0].fWeight,
     610           0 :                      outMC->fLabels[i/elsize].fClusterID[1].fMCID,outMC->fLabels[i/elsize].fClusterID[1].fWeight,
     611           0 :                      outMC->fLabels[i/elsize].fClusterID[2].fMCID,outMC->fLabels[i/elsize].fClusterID[2].fWeight
     612             :                      );
     613             :             }
     614           0 :           }
     615             :         }
     616           0 :       }
     617             :           
     618             : 
     619           0 :       AliHLTUInt32_t outSize = headerSize + clustersSize32*sizeof(AliHLTUInt32_t);
     620             :       
     621           0 :       if( size + outSize <= maxSize ){
     622             :         
     623           0 :         memcpy( outputPtr, outBlock, outSize );
     624             :         
     625           0 :         AliHLTComponentBlockData bd;
     626           0 :         FillBlockData( bd );
     627           0 :         bd.fOffset = size;
     628           0 :         bd.fSize = outSize;
     629           0 :         bd.fSpecification = iter->fSpecification;
     630           0 :         bd.fDataType = AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC;
     631           0 :         outputBlocks.push_back( bd );
     632           0 :         fBenchmark.AddOutput(bd.fSize);
     633           0 :         size+= bd.fSize;
     634           0 :         outputPtr+=bd.fSize;
     635           0 :       } else {
     636           0 :         HLTWarning( "Output buffer (%db) is too small, required %db", maxSize, size+outSize);
     637             :         iResult=-ENOSPC;
     638           0 :         break;
     639             :       }
     640             : 
     641           0 :       if( fDoMC && outMC && outMC->fCount>0 ){
     642           0 :         int s = sizeof(AliHLTTPCClusterMCData) + outMC->fCount*sizeof(AliHLTTPCClusterMCLabel);
     643           0 :         if( size + s <= maxSize ){
     644           0 :           memcpy( outputPtr, outMC, s );                  
     645           0 :           AliHLTComponentBlockData bdMCInfo;
     646           0 :           FillBlockData( bdMCInfo );
     647           0 :           bdMCInfo.fOffset = size;
     648           0 :           bdMCInfo.fSize = s;
     649           0 :           bdMCInfo.fSpecification = iter->fSpecification;
     650           0 :           bdMCInfo.fDataType = AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC;
     651           0 :           outputBlocks.push_back( bdMCInfo );
     652           0 :           fBenchmark.AddOutput(bdMCInfo.fSize);
     653           0 :           size+=bdMCInfo.fSize;
     654           0 :           outputPtr+=bdMCInfo.fSize; 
     655           0 :         } else {        
     656           0 :           HLTWarning( "Output buffer (%db) is too small, required %db", maxSize, size+s);
     657             :           iResult=-ENOSPC;
     658           0 :           break;
     659             :         }
     660           0 :       }
     661           0 :     }
     662             :  
     663           0 :   if( outBlock ) delete[] outBlock;
     664           0 :   if( allocOutMC ) delete[] allocOutMC;      
     665             :   
     666           0 :   if( iResult>=0 ){
     667             :     //
     668             :     // forward unpacked clusters if they are present
     669             :     // to forward input data, one should only forward the block descriptors, without copying the data. 
     670             :     // The framework will recognise that these blocks are forwarded, as they have fPtr field !=NULL, and take the data from fPtr pointer   
     671             :     //
     672           0 :     for( unsigned long ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
     673           0 :       const AliHLTComponentBlockData* iter = blocks+ndx;      
     674           0 :       if(  iter->fDataType == AliHLTTPCDefinitions::RawClustersDataType() || iter->fDataType == AliHLTTPCDefinitions::RawClustersDescriptorDataType() ){
     675           0 :         if( !iter->fPtr ) continue;
     676           0 :         fBenchmark.AddOutput(iter->fSize);
     677           0 :         outputBlocks.push_back( *iter );
     678           0 :       }
     679           0 :     } 
     680           0 :   }
     681             : 
     682           0 :   fBenchmark.Stop(0);  
     683           0 :   HLTInfo(fBenchmark.GetStatistics());
     684           0 :   fCFSupport.ReleaseEventMemory();
     685             :   return iResult;
     686           0 : }
     687             : 
     688             : 

Generated by: LCOV version 1.11