LCOV - code coverage report
Current view: top level - HLT/BASE/util - AliHLTBlockFilterComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 104 8.7 %
Date: 2016-06-14 17:26:59 Functions: 6 14 42.9 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the                          * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       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             : /// @file   AliHLTBlockFilterComponent.cxx
      20             : /// @author Matthias Richter
      21             : /// @date   
      22             : /// @brief  A simple data block filter and merger, merges block descriptors
      23             : ///
      24             : 
      25             : #include <cstdlib>
      26             : #include "AliHLTBlockFilterComponent.h"
      27             : #include "TString.h"
      28             : 
      29             : /** ROOT macro for the implementation of ROOT specific class methods */
      30           8 : ClassImp(AliHLTBlockFilterComponent)
      31             : 
      32             : AliHLTBlockFilterComponent::AliHLTBlockFilterComponent()
      33           3 :   : AliHLTProcessor()
      34           3 :   , fFilterRules()
      35           3 :   , fPrescalar(0)
      36           3 :   , fFirstEvent(0)
      37          15 : {
      38             :   // A data block merger and filter.
      39             :   // It merges data block descriptors fulfilling the filtering rules and
      40             :   // forwards the descriptors to the output. The actual data is not touched.
      41             :   //
      42             :   // Component ID: \b BlockFilter
      43             :   // Library: \b libAliHLTUtil.so
      44             :   // Input Data Types: kAliHLTAnyDataType
      45             :   // Output Data Types: according to parameter and input blocks
      46           6 : }
      47             : 
      48             : AliHLTBlockFilterComponent::~AliHLTBlockFilterComponent()
      49          18 : {
      50             :   // destructor
      51           9 : }
      52             : 
      53             : void AliHLTBlockFilterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
      54             : {
      55             :   // overloaded from AliHLTComponent
      56           0 :   list.clear();
      57           0 :   list.push_back(kAliHLTAnyDataType);
      58           0 : }
      59             : 
      60             : AliHLTComponentDataType AliHLTBlockFilterComponent::GetOutputDataType()
      61             : {
      62             :   // overloaded from AliHLTComponent
      63           0 :   if (fFilterRules.size()==1) return fFilterRules[0].fDataType;
      64           0 :   if (fFilterRules.size()==0) return kAliHLTAnyDataType;
      65           0 :   return kAliHLTMultipleDataType;
      66           0 : }
      67             : 
      68             : int AliHLTBlockFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
      69             : {
      70             :   // overloaded from AliHLTComponent
      71           0 :   tgtList.clear();
      72           0 :   AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
      73           0 :   while (desc!=fFilterRules.end()) {
      74           0 :     AliHLTComponentDataTypeList::iterator type=tgtList.begin();
      75           0 :     while (type!=tgtList.end()) {
      76           0 :       if (*type==(*desc).fDataType) break;
      77           0 :       type++;
      78             :     }
      79           0 :     if (type==tgtList.end()) tgtList.push_back((*desc).fDataType);
      80           0 :     desc++;
      81           0 :   }
      82           0 :   return tgtList.size();
      83           0 : }
      84             : 
      85             : void AliHLTBlockFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
      86             : {
      87             :   // overloaded from AliHLTComponent
      88           0 :   constBase=0;
      89           0 :   inputMultiplier=0.0; // there is no new data, just forwarded descriptors
      90           0 : }
      91             : 
      92             : int AliHLTBlockFilterComponent::DoInit( int argc, const char** argv )
      93             : {
      94             :   int iResult=0;
      95           0 :   TString argument="";
      96             :   int bMissingParam=0;
      97           0 :   AliHLTComponentBlockData rule;
      98           0 :   FillBlockData(rule);
      99           0 :   for (int i=0; i<argc && iResult>=0; i++) {
     100           0 :     argument=argv[i];
     101           0 :     if (argument.IsNull()) continue;
     102             : 
     103             :     // -datatype
     104           0 :     if (argument.CompareTo("-datatype")==0) {
     105           0 :       if ((bMissingParam=(i+2>=argc))) break;
     106             : 
     107           0 :       if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
     108             :         // the data type has already been set, add to list
     109             :         // and reset
     110           0 :         fFilterRules.push_back(rule);
     111           0 :         FillBlockData(rule);
     112             :       }
     113             : 
     114           0 :       SetDataType(rule.fDataType, argv[i+1], argv[i+2]);
     115             :       i+=2;
     116             : 
     117             :       // -origin
     118           0 :     } else if (argument.CompareTo("-origin")==0) {
     119           0 :       if ((bMissingParam=(i+1>=argc))) break;
     120             : 
     121           0 :       if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
     122             :         // the data type has already been set, add to list
     123             :         // and reset
     124           0 :         fFilterRules.push_back(rule);
     125           0 :         FillBlockData(rule);
     126             :       }
     127             : 
     128           0 :       SetDataType(rule.fDataType, NULL, argv[i+1]);
     129             :       i+=1;
     130             : 
     131             :       // -typeid
     132           0 :     } else if (argument.CompareTo("-typeid")==0) {
     133           0 :       if ((bMissingParam=(i+1>=argc))) break;
     134             : 
     135           0 :       if (!MatchExactly(rule.fDataType,kAliHLTAnyDataType)) {
     136             :         // the data type has already been set, add to list
     137             :         // and reset
     138           0 :         fFilterRules.push_back(rule);
     139           0 :         FillBlockData(rule);
     140             :       }
     141             : 
     142           0 :       SetDataType(rule.fDataType, argv[i+1], NULL);
     143             :       i+=1;
     144             : 
     145             :       // -dataspec
     146           0 :     } else if (argument.CompareTo("-dataspec")==0) {
     147           0 :       if ((bMissingParam=(++i>=argc))) break;
     148             : 
     149           0 :       if (rule.fSpecification!=kAliHLTVoidDataSpec) {
     150             :         // the specification has already been set, add to list
     151             :         // and reset
     152           0 :         fFilterRules.push_back(rule);
     153           0 :         FillBlockData(rule);
     154             :       }
     155             : 
     156           0 :       TString parameter(argv[i]);
     157           0 :       parameter.Remove(TString::kLeading, ' '); // remove all blanks
     158           0 :       char* pRemnant=NULL;
     159           0 :       rule.fSpecification=strtoul(parameter.Data(), &pRemnant, 0);
     160           0 :       if (pRemnant!=NULL && pRemnant[0]!=0) {
     161           0 :         HLTError("invalid parameter/remnant (%s) for argument %s, number expected", pRemnant, argument.Data());
     162             :         iResult=-EINVAL;
     163           0 :       }
     164             :       // -prescalar
     165           0 :     } else if (argument.CompareTo("-prescalar")==0) {
     166           0 :       if ((bMissingParam=(++i>=argc))) break;
     167           0 :       TString parameter(argv[i]);
     168           0 :       fPrescalar=parameter.Atoi();
     169             :       // -skip-events
     170           0 :     } else if (argument.CompareTo("-skip-events")==0) {
     171           0 :       if ((bMissingParam=(++i>=argc))) break;
     172           0 :       TString parameter(argv[i]);
     173           0 :       fFirstEvent=parameter.Atoi();
     174           0 :     } else {
     175           0 :       HLTError("unknown argument %s", argument.Data());
     176             :       iResult=-EINVAL;
     177           0 :       break;
     178             :     }
     179             :   }
     180           0 :   if (iResult>=0 && (rule.fSpecification!=kAliHLTVoidDataSpec || !MatchExactly(rule.fDataType,kAliHLTAnyDataType))) {
     181             :     // add the pending rule
     182           0 :     fFilterRules.push_back(rule);
     183           0 :     FillBlockData(rule);
     184             :   }
     185             :   return iResult;
     186           0 : }
     187             : 
     188             : int AliHLTBlockFilterComponent::DoDeinit()
     189             : {
     190             :   int iResult=0;
     191           0 :   fFilterRules.clear();
     192           0 :   return iResult;
     193             : }
     194             : 
     195             : int AliHLTBlockFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
     196             :                                          const AliHLTComponentBlockData* /*blocks*/, 
     197             :                                          AliHLTComponentTriggerData& /*trigData*/,
     198             :                                          AliHLTUInt8_t* /*outputPtr*/, 
     199             :                                          AliHLTUInt32_t& size,
     200             :                                          AliHLTComponentBlockDataList& /*outputBlocks*/ )
     201             : {
     202             :   // overloaded from AliHLTProcessor: event processing
     203             :   int iResult=0;
     204           0 :   if ((fPrescalar==0 || ((GetEventCount())%fPrescalar)==0) &&
     205           0 :       GetEventCount()>=(int)fFirstEvent) {
     206           0 :   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
     207           0 :        pBlock!=NULL; 
     208           0 :        pBlock=GetNextInputBlock()) {
     209           0 :     if (IsSelected(*pBlock)) {
     210             :       HLTDebug("block type %s %#x (ptr=%p offset=%d size=%d) selected by filter rules", 
     211             :                DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, 
     212             :                pBlock->fPtr, pBlock->fOffset, pBlock->fSize);
     213           0 :       Forward();
     214           0 :     } else {
     215             :       HLTDebug("block type %s %#x discarded by filter rules", DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification);
     216             :     }
     217             :   }
     218           0 :   }
     219           0 :   size=0;
     220           0 :   return iResult;
     221             : }
     222             : 
     223             : int AliHLTBlockFilterComponent::IsSelected(const AliHLTComponentBlockData& block)
     224             : {
     225             :   // check if a data is selected by the configured criteria
     226           0 :   AliHLTComponentBlockDataList::iterator desc=fFilterRules.begin();
     227             :   //HLTDebug("check block: %s spec %#x", DataType2Text(block.fDataType, 1).c_str(), block.fSpecification);
     228           0 :   if (desc==fFilterRules.end()) return 1; // no filter rules
     229             :   do {
     230             :     // match if
     231             :     // 1. data types match or filter data type not set
     232             :     // 2. data spec match or filter data wpec not set
     233             :     // 3. either filter data type or spec is set
     234             :     //HLTDebug("check rule : %s spec %#x", DataType2Text((*desc).fDataType, 2).c_str(), block.fSpecification);
     235           0 :     if (((*desc).fDataType==block.fDataType) &&
     236           0 :         ((*desc).fSpecification==block.fSpecification || (*desc).fSpecification==kAliHLTVoidDataSpec) &&
     237           0 :         (!MatchExactly((*desc).fDataType,kAliHLTAnyDataType) || (*desc).fSpecification!=kAliHLTVoidDataSpec)) {
     238           0 :       return 1;
     239             :     }
     240           0 :   } while (++desc!=fFilterRules.end());
     241             :   
     242           0 :   return 0;
     243           0 : }

Generated by: LCOV version 1.11