LCOV - code coverage report
Current view: top level - HLT/TPCLib - AliHLTTPCTrackMCMarkerComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 7 132 5.3 %
Date: 2016-06-14 17:26:59 Functions: 4 17 23.5 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : // **************************************************************************
       4             : // This file is property of and copyright by the ALICE HLT Project          *
       5             : // ALICE Experiment at CERN, All rights reserved.                           *
       6             : //                                                                          *
       7             : // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
       8             : //                  for The ALICE HLT Project.                              *
       9             : //                                                                          *
      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             : //                                                                          *
      18             : //***************************************************************************
      19             : 
      20             : /// @file   AliHLTTPCTrackMCMarkerComponent.cxx
      21             : /// @author Matthias Kretz
      22             : /// @date
      23             : /// @brief  Marker component for TPC cluster mc labels.
      24             : ///
      25             : 
      26             : #include "AliHLTTPCTrackMCMarkerComponent.h"
      27             : #include "AliHLTTPCCADef.h"
      28             : #include "AliHLTTPCDefinitions.h"
      29             : #include "AliHLTTPCSpacePointData.h"
      30             : #include "AliHLTTPCClusterMCData.h"
      31             : 
      32             : #include "AliCDBEntry.h"
      33             : #include "AliCDBManager.h"
      34             : #include "TObjString.h"
      35             : #include "TObjArray.h"
      36             : #include "AliHLTExternalTrackParam.h"
      37             : #include "AliHLTTrackMCLabel.h"
      38             : #include <climits>
      39             : #include <cstdlib>
      40             : #include <cerrno>
      41             : #include <algorithm>
      42             : 
      43             : // ROOT macro for the implementation of ROOT specific class methods
      44           6 : ClassImp( AliHLTTPCTrackMCMarkerComponent )
      45             : 
      46             : 
      47           3 : AliHLTTPCTrackMCMarkerComponent::AliHLTTPCTrackMCMarkerComponent()
      48          15 : {
      49             :   // see header file for class documentation
      50        1302 :   for( int i=0; i<36*6; i++ ){
      51         648 :     fClusterLabels[i] = 0;    
      52             :   }
      53           6 : }
      54             : 
      55             : // Public functions to implement AliHLTComponent's interface.
      56             : // These functions are required for the registration process
      57             : 
      58             : const char *AliHLTTPCTrackMCMarkerComponent::GetComponentID()
      59             : {
      60             :   // see header file for class documentation
      61         534 :   return "TPCTrackMCMarker";
      62             : }
      63             : 
      64             : void AliHLTTPCTrackMCMarkerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list )
      65             : {
      66             :   // see header file for class documentation
      67           0 :   list.clear();
      68           0 :   list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
      69           0 :   list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo);
      70           0 : }
      71             : 
      72             : AliHLTComponentDataType AliHLTTPCTrackMCMarkerComponent::GetOutputDataType()
      73             : {
      74             :   // see header file for class documentation
      75           0 :   return kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
      76             : }
      77             : 
      78             : void AliHLTTPCTrackMCMarkerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
      79             : {
      80             :   // see header file for class documentation
      81           0 :   constBase = 0;
      82           0 :   inputMultiplier = 1.0;
      83           0 : }
      84             : 
      85             : AliHLTComponent *AliHLTTPCTrackMCMarkerComponent::Spawn()
      86             : {
      87             :   // see header file for class documentation
      88           0 :   return new AliHLTTPCTrackMCMarkerComponent;
      89           0 : }
      90             : 
      91             : 
      92             : 
      93             : 
      94             : void AliHLTTPCTrackMCMarkerComponent::SetDefaultConfiguration()
      95             : {
      96             :   // Set default configuration for the CA merger component
      97             :   // Some parameters can be later overwritten from the OCDB
      98           0 : }
      99             : 
     100             : int AliHLTTPCTrackMCMarkerComponent::ReadConfigurationString(  const char* arguments )
     101             : {
     102             :   // Set configuration parameters for the CA merger component from the string
     103             : 
     104             :   int iResult = 0;
     105           0 :   if ( !arguments ) return iResult;
     106             : 
     107           0 :   TString allArgs = arguments;
     108           0 :   TString argument;
     109             :   int bMissingParam = 0;
     110             : 
     111           0 :   TObjArray* pTokens = allArgs.Tokenize( " " );
     112             :   
     113           0 :   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
     114             :   
     115           0 :   for ( int i = 0; i < nArgs; i++ ) {
     116           0 :     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
     117           0 :     if ( argument.IsNull() ) continue;
     118             : 
     119           0 :     HLTError( "Unknown option \"%s\"", argument.Data() );
     120             :     iResult = -EINVAL;
     121           0 :   }
     122           0 :   delete pTokens;
     123             : 
     124           0 :   if ( bMissingParam ) {
     125           0 :     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
     126             :     iResult = -EINVAL;
     127           0 :   }
     128             : 
     129             :   return iResult;
     130           0 : }
     131             : 
     132             : 
     133             : int AliHLTTPCTrackMCMarkerComponent::ReadCDBEntry( const char* /*cdbEntry*/, const char* /*chainId*/ )
     134             : {
     135             :   // see header file for class documentation
     136             : 
     137             :   // no settings for a moment, no CDB path, threfore return
     138             : 
     139           0 :   return 0;
     140             : /*
     141             :   const char* defaultNotify = "";
     142             : 
     143             :   if ( !cdbEntry ) {
     144             :     cdbEntry = "HLT/ConfigTPC/TPCTrackMCMarker";
     145             :     defaultNotify = " (default)";
     146             :     chainId = 0;
     147             :   }
     148             : 
     149             :   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
     150             :   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
     151             : 
     152             :   if ( !pEntry ) {
     153             :     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
     154             :     return -EINVAL;
     155             :   }
     156             : 
     157             :   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
     158             : 
     159             :   if ( !pString ) {
     160             :     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
     161             :     return -EINVAL;
     162             :   }
     163             : 
     164             :   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
     165             : 
     166             :   return  ReadConfigurationString( pString->GetString().Data() );
     167             : */
     168             : }
     169             : 
     170             : 
     171             : 
     172             : int AliHLTTPCTrackMCMarkerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
     173             : {
     174             :   // Configure the component
     175             :   // There are few levels of configuration,
     176             :   // parameters which are set on one step can be overwritten on the next step
     177             : 
     178             :   //* read hard-coded values
     179             : 
     180           0 :   SetDefaultConfiguration();
     181             : 
     182             :   //* read the default CDB entry
     183             : 
     184           0 :   int iResult1 = ReadCDBEntry( NULL, chainId );
     185             : 
     186             :   //* read the actual CDB entry if required
     187             : 
     188           0 :   int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
     189             : 
     190             :   //* read extra parameters from input (if they are)
     191             : 
     192             :   int iResult3 = 0;
     193             : 
     194           0 :   if ( commandLine && commandLine[0] != '\0' ) {
     195           0 :     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
     196           0 :     iResult3 = ReadConfigurationString( commandLine );
     197           0 :   }
     198             : 
     199           0 :   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
     200             : }
     201             : 
     202             : 
     203             : 
     204             : 
     205             : int AliHLTTPCTrackMCMarkerComponent::DoInit( int argc, const char** argv )
     206             : {
     207             :   // see header file for class documentation
     208             : 
     209           0 :   TString arguments = "";
     210           0 :   for ( int i = 0; i < argc; i++ ) {
     211           0 :     if ( !arguments.IsNull() ) arguments += " ";
     212           0 :     arguments += argv[i];
     213             :   }
     214             : 
     215           0 :   return Configure( NULL, NULL, arguments.Data()  );
     216           0 : }
     217             : 
     218             : 
     219             : int AliHLTTPCTrackMCMarkerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
     220             : {
     221             :   // Reconfigure the component from OCDB
     222             : 
     223           0 :   return Configure( cdbEntry, chainId, NULL );
     224             : }
     225             : 
     226             : 
     227             : 
     228             : int AliHLTTPCTrackMCMarkerComponent::DoDeinit()
     229             : {
     230             :   // see header file for class documentation
     231             : 
     232           0 :   return 0;
     233             : }
     234             : 
     235             : Int_t AliHLTTPCTrackMCMarkerComponent::GetTrackMCLabel( unsigned int *hits, int nHits )
     236             : {
     237             :   // get MC label for the track  
     238             : 
     239             :   Int_t mcLabel = -1;
     240             :             
     241           0 :   std::vector<int> labels;
     242             : 
     243           0 :   for( Int_t ih=0; ih<nHits; ih++){
     244           0 :     UInt_t id = hits[ih];
     245           0 :     int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
     246           0 :     int iPatch = AliHLTTPCSpacePointData::GetPatch(id);
     247           0 :     unsigned int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
     248           0 :     if( iSlice<0 || iSlice>=36 || iPatch<0 || iPatch>5 ){
     249           0 :       HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
     250             :                iSlice, iPatch,iCluster );
     251           0 :       continue;
     252             :     }
     253           0 :     AliHLTTPCClusterMCData *patchLabels = fClusterLabels[iSlice*6 + iPatch];
     254           0 :     if( !patchLabels ) continue;
     255           0 :     if( iCluster >= patchLabels->fCount ){
     256           0 :       HLTError("TPC slice %d, patch %d: ClusterID==%d >= N MC labels==%d ",
     257             :                iSlice, iPatch,iCluster, patchLabels->fCount);
     258           0 :       continue;
     259             :     }
     260           0 :     AliHLTTPCClusterMCLabel &lab = patchLabels->fLabels[iCluster];           
     261           0 :     if ( lab.fClusterID[0].fMCID >= 0 ) labels.push_back( lab.fClusterID[0].fMCID );
     262           0 :     if ( lab.fClusterID[1].fMCID >= 0 ) labels.push_back( lab.fClusterID[1].fMCID );
     263           0 :     if ( lab.fClusterID[2].fMCID >= 0 ) labels.push_back( lab.fClusterID[2].fMCID );
     264           0 :   }
     265             :           
     266           0 :   std::sort( labels.begin(), labels.end() );
     267             :           
     268           0 :   labels.push_back( -1 ); // put -1 to the end
     269             :           
     270             :   int labelMax = -1, labelCur = -1, nLabelsMax = 0, nLabelsCurr = 0;
     271           0 :   for ( unsigned int iLab = 0; iLab < labels.size(); iLab++ ) {
     272           0 :     if ( labels[iLab] != labelCur ) {         
     273           0 :       if ( labelCur >= 0 && nLabelsMax< nLabelsCurr ) {
     274             :         nLabelsMax = nLabelsCurr;
     275             :         labelMax = labelCur;
     276           0 :       }
     277           0 :       labelCur = labels[iLab];
     278             :       nLabelsCurr = 0;
     279           0 :     }
     280           0 :     nLabelsCurr++;
     281             :   }
     282             :   
     283           0 :   if( labelMax>=0 && nLabelsMax < 0.9 * nHits ) labelMax = -labelMax;
     284             :   
     285             :   mcLabel = labelMax;
     286             : 
     287             :   return mcLabel;
     288           0 : }
     289             : 
     290             : 
     291             : int AliHLTTPCTrackMCMarkerComponent::DoEvent( const AliHLTComponentEventData &evtData,
     292             :     const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
     293             :     AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
     294             : {
     295             :   // see header file for class documentation
     296             : 
     297             :   int iResult = 0;
     298           0 :   unsigned int maxBufferSize = size;
     299             : 
     300           0 :   size = 0;
     301             : 
     302           0 :   if ( !outputPtr ) {
     303           0 :     return -ENOSPC;
     304             :   }
     305           0 :   if ( !IsDataEvent() ) {
     306           0 :     return 0;
     307             :   }
     308             : 
     309           0 :   for( int i=0; i<36*6; i++ ){
     310           0 :     fClusterLabels[i] = 0;
     311             :   }
     312             : 
     313           0 :   int nBlocks = (int)evtData.fBlockCnt;
     314             : 
     315             :   int nInputMCLabels = 0;
     316             :   int nInputTracks = 0;
     317             : 
     318             :   // first read all the MC information
     319           0 :   for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
     320           0 :     const AliHLTComponentBlockData* iter = blocks+ndx;
     321           0 :     if(iter->fDataType == AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo ) {
     322           0 :       Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
     323           0 :       Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
     324           0 :       fClusterLabels[ slice*6 + patch] = (AliHLTTPCClusterMCData*)iter->fPtr;
     325           0 :       nInputMCLabels+=fClusterLabels[ slice*6 + patch]->fCount;
     326           0 :     }
     327             :   }
     328             :       
     329             :   // read tracks and write output
     330             : 
     331             :   
     332             :   unsigned int mySize = 0;
     333             :   
     334           0 :   AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr );
     335           0 :   AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels;
     336             : 
     337           0 :   mySize =   ( ( AliHLTUInt8_t * )currOutLabel ) -  ( ( AliHLTUInt8_t * )outPtr );
     338             : 
     339           0 :   outPtr->fCount = 0;
     340             : 
     341           0 :   for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
     342           0 :     const AliHLTComponentBlockData* iter = blocks+ndx;
     343             :         
     344           0 :     if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){          
     345           0 :       AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
     346           0 :       int nTracks = dataPtr->fCount;
     347           0 :       AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
     348           0 :       for( int itr=0; itr<nTracks; itr++ ){
     349           0 :         nInputTracks++;
     350           0 :         Int_t mcLabel = GetTrackMCLabel( currTrack->fPointIDs, currTrack->fNPoints );  
     351             : 
     352           0 :         currOutLabel->fTrackID = currTrack->fTrackID;
     353           0 :         currOutLabel->fMCLabel = mcLabel;
     354             : 
     355           0 :         if ( mySize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) {
     356           0 :           HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
     357             :           iResult = -ENOSPC;
     358           0 :           break;
     359             :         }
     360           0 :         mySize += sizeof(AliHLTTrackMCLabel);
     361           0 :         currOutLabel++;
     362           0 :         outPtr->fCount++;
     363             : 
     364           0 :         unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
     365           0 :         currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + dSize );
     366           0 :       }
     367           0 :     }
     368             :   }
     369             :   
     370             : 
     371           0 :   AliHLTComponentBlockData resultData;
     372           0 :   FillBlockData( resultData );
     373           0 :   resultData.fOffset = 0;
     374           0 :   resultData.fSize = mySize;
     375           0 :   resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
     376           0 :   resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
     377           0 :   outputBlocks.push_back( resultData );
     378           0 :   size = resultData.fSize;
     379             : 
     380           0 :   HLTInfo( "TrackMCMarker:: input %d labels, %d tracks, output %d labels", nInputMCLabels, nInputTracks,outPtr->fCount );
     381             : 
     382             :   return iResult;
     383           0 : }
     384             : 

Generated by: LCOV version 1.11