LCOV - code coverage report
Current view: top level - HLT/TPCLib/offline - AliHLTTPCDigitPublisherComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 113 9.7 %
Date: 2016-06-14 17:26:59 Functions: 7 15 46.7 %

          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: 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   AliHLTTPCDigitPublisherComponent.cxx
      20             :     @author Matthias Richter
      21             :     @date   
      22             :     @brief  TPC digit publisher component (input from offline).
      23             : */
      24             : 
      25             : // see header file for class documentation
      26             : // or
      27             : // refer to README to build package
      28             : // or
      29             : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
      30             : 
      31             : #include "AliHLTTPCDigitPublisherComponent.h"
      32             : #include "AliRunLoader.h"
      33             : #include "AliLog.h"
      34             : #include "TTree.h"
      35             : #include "AliHLTTPCDigitData.h"
      36             : #include "AliHLTTPCDefinitions.h"
      37             : #include "AliHLTTPCFileHandler.h"
      38             : 
      39             : /** ROOT macro for the implementation of ROOT specific class methods */
      40           6 : ClassImp(AliHLTTPCDigitPublisherComponent)
      41             : 
      42           3 : AliHLTTPCDigitPublisherComponent::AliHLTTPCDigitPublisherComponent()
      43             :   :
      44           3 :   fMaxSize(200000), // just a number to start with
      45           3 :   fMinSlice(-1),
      46           3 :   fMinPart(-1)
      47          15 : {
      48             :   // see header file for class documentation
      49             :   // or
      50             :   // refer to README to build package
      51             :   // or
      52             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      53           6 : }
      54             : 
      55             : AliHLTTPCFileHandler* AliHLTTPCDigitPublisherComponent::fgpFileHandler=NULL;
      56             : int AliHLTTPCDigitPublisherComponent::fgFileHandlerInstances=0;
      57             : int AliHLTTPCDigitPublisherComponent::fgCurrEvent=-1;
      58             : 
      59           0 : AliHLTTPCDigitPublisherComponent::~AliHLTTPCDigitPublisherComponent()
      60          18 : {
      61             :   // see header file for class documentation
      62           3 :   if (fgpFileHandler!=NULL && fgFileHandlerInstances<=0) {
      63           0 :     HLTWarning("improper state, de-initialization missing");
      64           0 :     DoDeinit();
      65             :   }
      66           9 : }
      67             : 
      68             : const char* AliHLTTPCDigitPublisherComponent::GetComponentID()
      69             : {
      70             :   // see header file for class documentation
      71         492 :   return "TPCDigitPublisher";
      72             : }
      73             : 
      74             : AliHLTComponentDataType AliHLTTPCDigitPublisherComponent::GetOutputDataType()
      75             : {
      76           0 :   return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
      77             : }
      78             : 
      79             : void AliHLTTPCDigitPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
      80             : {
      81           0 :   constBase=fMaxSize;
      82           0 :   inputMultiplier=1;
      83           0 : }
      84             : 
      85             : AliHLTComponent* AliHLTTPCDigitPublisherComponent::Spawn()
      86             : {
      87             :   // see header file for class documentation
      88           0 :   return new AliHLTTPCDigitPublisherComponent;
      89           0 : }
      90             : 
      91             : int AliHLTTPCDigitPublisherComponent::DoInit( int argc, const char** argv )
      92             : {
      93             :   // see header file for class documentation
      94             :   int iResult=0;
      95             : 
      96             :   // scan arguments
      97           0 :   TString argument="";
      98             :   int bMissingParam=0;
      99           0 :   for (int i=0; i<argc && iResult>=0; i++) {
     100           0 :     argument=argv[i];
     101           0 :     if (argument.IsNull()) continue;
     102             : 
     103             :     // -slice
     104           0 :     if (argument.CompareTo("-slice")==0) {
     105           0 :       if ((bMissingParam=(++i>=argc))) break;
     106           0 :       TString parameter(argv[i]);
     107           0 :       parameter.Remove(TString::kLeading, ' '); // remove all blanks
     108           0 :       if (parameter.IsDigit()) {
     109           0 :         fMinSlice=parameter.Atoi();
     110           0 :       } else {
     111           0 :         HLTError("wrong parameter for argument %s, number expected", argument.Data());
     112             :         iResult=-EINVAL;
     113             :       }
     114             :       // -partition
     115           0 :     } else if (argument.CompareTo("-partition")==0) {
     116           0 :       if ((bMissingParam=(++i>=argc))) break;
     117           0 :       TString parameter(argv[i]);
     118           0 :       parameter.Remove(TString::kLeading, ' '); // remove all blanks
     119           0 :       if (parameter.IsDigit()) {
     120           0 :         fMinPart=parameter.Atoi();
     121           0 :       } else {
     122           0 :         HLTError("wrong parameter for argument %s, number expected", argument.Data());
     123             :         iResult=-EINVAL;
     124             :       }
     125           0 :     } else {
     126           0 :       HLTError("unknown argument %s", argument.Data());
     127             :       iResult=-EINVAL;
     128             :     }
     129             :   }
     130           0 :   if (bMissingParam) {
     131           0 :     HLTError("missing parameter for argument %s", argument.Data());
     132             :     iResult=-EINVAL;
     133           0 :   }
     134             : 
     135           0 :   if (fMinSlice<0) {
     136           0 :     HLTError("slice no required");
     137             :     iResult=-EINVAL;
     138           0 :   }
     139             : 
     140           0 :   if (fMinPart<0) {
     141           0 :     HLTError("partition (patch) no required");
     142             :     iResult=-EINVAL;
     143           0 :   }
     144             : 
     145           0 :   if (iResult<0) return iResult;
     146             : 
     147             :   // fetch runLoader instance from interface
     148           0 :   AliRunLoader* pRunLoader= AliRunLoader::Instance();   //GetRunLoader();
     149           0 :   if (pRunLoader) {
     150           0 :     if (fgpFileHandler==NULL) {
     151           0 :       fgpFileHandler=new AliHLTTPCFileHandler;
     152           0 :       fgCurrEvent=-1;
     153           0 :       fgFileHandlerInstances=1;
     154           0 :     } else {
     155           0 :       fgFileHandlerInstances++;
     156             :       //HLTDebug("publisher %p: %d references to file handler instance", this, fgFileHandlerInstances);
     157             :     }
     158           0 :     if (fgpFileHandler) {
     159           0 :       if (!fgpFileHandler->SetAliInput(pRunLoader)) {
     160             :         iResult=-EFAULT;
     161           0 :       }
     162             :     } else {
     163           0 :       AliErrorStream() << "can not allocate file handler object" << endl;
     164             :       iResult=-ENOMEM;
     165             :     }
     166             :   } else {
     167           0 :     AliErrorStream() << "can not get runLoader" << endl;
     168             :     iResult=-EFAULT;
     169             :   }
     170             :   return iResult;
     171           0 : }
     172             : 
     173             : int AliHLTTPCDigitPublisherComponent::DoDeinit()
     174             : {
     175             :   // see header file for class documentation
     176             :   int iResult=0;
     177           0 :   if (fgCurrEvent>=0) {
     178           0 :     fgpFileHandler->FreeDigitsTree();
     179           0 :     fgCurrEvent=-1;
     180           0 :   }
     181             :   //HLTDebug("publisher %p: %d references to file handler instance", this, fgFileHandlerInstances);
     182           0 :   if (--fgFileHandlerInstances==0 && fgpFileHandler!=NULL) {
     183             :     try {
     184           0 :       if (fgpFileHandler) {
     185           0 :         delete fgpFileHandler;
     186             :       }
     187             :     }
     188             :     catch (...) {
     189             :       HLTFatal("exeption during object cleanup");
     190             :       iResult=-EFAULT;
     191             :     }
     192           0 :     fgpFileHandler=NULL;
     193           0 :   }
     194           0 :   return iResult;
     195             : }
     196             : 
     197             : int AliHLTTPCDigitPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
     198             :                                                AliHLTComponentTriggerData& /*trigData*/,
     199             :                                                AliHLTUInt8_t* outputPtr, 
     200             :                                                AliHLTUInt32_t& osize,
     201             :                                                vector<AliHLTComponentBlockData>& outputBlocks)
     202             : {
     203             :   // see header file for class documentation
     204             :   int iResult=0;
     205           0 :   AliHLTUInt32_t capacity=osize;
     206           0 :   osize=0;
     207             : 
     208             :   // process data events only
     209           0 :   if (!IsDataEvent()) return 0;
     210             : 
     211           0 :   if (outputPtr==NULL || capacity==0) {
     212           0 :     HLTError("no target buffer provided");
     213           0 :     return -EFAULT;
     214             :   }
     215             : 
     216           0 :   if (fgpFileHandler) {
     217           0 :     int event=GetEventCount();
     218           0 :     AliHLTTPCUnpackedRawData* pTgt=reinterpret_cast<AliHLTTPCUnpackedRawData*>(outputPtr);
     219           0 :     if (pTgt) {
     220           0 :       UInt_t nrow=0;
     221           0 :       UInt_t tgtSize=capacity-sizeof(AliHLTTPCUnpackedRawData);
     222           0 :       if (fgCurrEvent>=0 && fgCurrEvent!=event) {
     223             :         HLTDebug("new event %d, free digit tree for event %d", event, fgCurrEvent);
     224           0 :         fgpFileHandler->FreeDigitsTree();
     225           0 :       }
     226           0 :       fgCurrEvent=event;
     227             :       HLTDebug("converting digits for slice %d partition %d", fMinSlice, fMinPart);
     228           0 :       fgpFileHandler->Init(fMinSlice,fMinPart);
     229           0 :       AliHLTTPCDigitRowData* pData=fgpFileHandler->AliDigits2Memory(nrow, event, reinterpret_cast<Byte_t*>(pTgt->fDigits), &tgtSize);
     230           0 :       if (pData==NULL && tgtSize>0 && tgtSize>fMaxSize) {
     231             :         HLTDebug("target buffer too small: %d byte required, %d available", tgtSize+sizeof(AliHLTTPCUnpackedRawData), capacity);
     232             :         // indicate insufficient buffer size, on occasion the frameworks calls
     233             :         // again with the corrected buffer 
     234           0 :         fMaxSize=tgtSize;
     235             :         iResult=-ENOSPC;
     236           0 :       } else if (pData!=pTgt->fDigits) {
     237           0 :         HLTError("can not read directly into output buffer");
     238           0 :         try {delete pData;}
     239             :         catch (...) {/* no action */}
     240             :         iResult=-EIO;
     241           0 :       } else {
     242           0 :         osize=tgtSize+sizeof(AliHLTTPCUnpackedRawData);
     243           0 :         AliHLTComponentBlockData bd;
     244           0 :         FillBlockData( bd );
     245           0 :         bd.fOffset = 0;
     246           0 :         bd.fSize = osize;
     247           0 :         bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(fMinSlice, fMinSlice, fMinPart, fMinPart);
     248           0 :         outputBlocks.push_back( bd );
     249             :         HLTDebug("added AliHLTTPCUnpackedRawData size %d, first row %d nof digits %d", osize, pTgt->fDigits->fRow, pTgt->fDigits->fNDigit);
     250           0 :       }
     251           0 :     }
     252           0 :   } else {
     253           0 :     AliErrorStream() << "component not initialized" << endl;
     254             :     iResult=-EFAULT;
     255             :   }
     256           0 :   return iResult;
     257           0 : }

Generated by: LCOV version 1.11