LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTDumpTask.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 65 1.5 %
Date: 2016-06-14 17:26:59 Functions: 1 14 7.1 %

          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   AliHLTDumpTask.cxx
      20             :     @author Matthias Richter
      21             :     @date   
      22             :     @brief  Base class for data sinks with direct buffer access.
      23             : */
      24             : 
      25             : #include "AliHLTDumpTask.h"
      26             : 
      27             : /** ROOT macro for the implementation of ROOT specific class methods */
      28         126 : ClassImp(AliHLTDumpTask)
      29             : 
      30             : AliHLTDumpTask::AliHLTDumpTask(const char* chains)
      31             :   :
      32           0 :   AliHLTTask(),
      33           0 :   fpDummyTask(NULL),
      34           0 :   fpDummyConfiguration(NULL),
      35           0 :   fBlocks()
      36           0 : {
      37             :   // see header file for class documentation
      38             :   // or
      39             :   // refer to README to build package
      40             :   // or
      41             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      42           0 :   if (chains && chains[0]!=0) SetChains(chains);
      43           0 : }
      44             : 
      45           0 : AliHLTDumpTask::~AliHLTDumpTask()
      46           0 : {
      47             :   // see header file for class documentation
      48             : 
      49             :   // UnsetTarget called automatically
      50           0 :   if (fpDummyTask) delete fpDummyTask;
      51           0 :   fpDummyTask=NULL;
      52             : 
      53           0 :   if (fpDummyConfiguration) delete fpDummyConfiguration;
      54           0 :   fpDummyConfiguration=NULL;
      55             : 
      56           0 :   if (fpConfiguration) delete fpConfiguration;
      57           0 :   fpConfiguration=NULL;
      58           0 : }
      59             : 
      60             : int AliHLTDumpTask::SetChains(const char* chains)
      61             : {
      62             :   // see header file for class documentation
      63           0 :   if (!chains || chains[0]==0) {
      64           0 :     HLTError("invalid chain id string");
      65           0 :     return -EINVAL;
      66             :   }
      67           0 :   TString taskname=chains;
      68           0 :   taskname.ReplaceAll(" ", "_");
      69           0 :   taskname+="_hltDumpTask";
      70             : 
      71             :   // This is just a trick to use the existing Task handling, especially the
      72             :   // ProcessTask function.
      73             :   // 1. The 'BlockFilter' just forwards the data blocks of all specified chains
      74             :   // 2. A dummy task is added to the target list in order to set the data segments
      75             :   //    after forwarding. In case of an empty target list the data is just discarded.
      76             :   // That's maybe not the most elegant solution but far less awkward as one would
      77             :   // expect.
      78           0 :   fpConfiguration=new AliHLTConfiguration(taskname.Data(), "BlockFilter", chains, NULL);
      79           0 :   TString dummyname=chains;
      80           0 :   dummyname.ReplaceAll(" ", "_");
      81           0 :   dummyname+="_never_used_dummy_";
      82           0 :   fpDummyConfiguration=new AliHLTConfiguration(dummyname.Data(), "BlockFilter", taskname.Data(), NULL);
      83           0 :   if (fpDummyConfiguration) {
      84           0 :     fpDummyTask=new AliHLTTask(fpDummyConfiguration);
      85           0 :     SetTarget(fpDummyTask);
      86           0 :     fpDummyTask->SetDependency(this);
      87             :   }
      88             :   return 0;
      89           0 : }
      90             : 
      91             : int AliHLTDumpTask::CustomInit(AliHLTComponentHandler* pCH)
      92             : {
      93             :   // see header file for class documentation
      94           0 :   if (!fpDummyTask) return -ENOENT;
      95           0 :   return fpDummyTask->Init(NULL, pCH);
      96           0 : }
      97             : 
      98             : int AliHLTDumpTask::CustomCleanup()
      99             : {
     100             :   // see header file for class documentation
     101           0 :   if (!fpDummyTask) return -ENOENT;
     102           0 :   return fpDummyTask->Deinit();
     103           0 : }
     104             : 
     105             : const char* AliHLTDumpTask::GetSourceChains() const
     106             : {
     107             :   // see header file for class documentation
     108           0 :   if (!fpConfiguration) return "";
     109           0 :   return fpConfiguration->GetSourceSettings();
     110           0 : }
     111             : 
     112             : const AliHLTComponentBlockDataList& AliHLTDumpTask::GetDataBlocks()
     113             : {
     114             :   // see header file for class documentation
     115           0 :   if (fBlocks.size()>0) return fBlocks;
     116           0 :   if (fpDataBuffer) {
     117           0 :     if (!fpDataBuffer->FindConsumer(fpDummyTask->GetComponent())) {
     118             :       // in order to subscribe to the buffers the dummy consumer
     119             :       // needs to be set. The dummy task is not in the AliHLTSystem chain
     120             :       // and therefor not automatically set.
     121           0 :       fpDataBuffer->SetConsumer(fpDummyTask->GetComponent());
     122           0 :     }
     123           0 :     fBlocks.clear();
     124           0 :     if (fpDataBuffer->GetNofSegments()>0 
     125           0 :         && fpDataBuffer->FindConsumer(fpDummyTask->GetComponent(), 0 /*search only among pending consumers*/)>0) {
     126           0 :       if (fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlocks)>=0) {
     127           0 :         return fBlocks;
     128             :       } else {
     129           0 :         HLTError("failed to subscribe to data buffer");
     130             :       }
     131             :     }
     132             :   } else {
     133             :     // 2008-08-07 this is not a failure condition
     134             :     // If the chain has not been processed because LocalReconstruction
     135             :     // is not enabled, the task will be empty
     136             :     //HLTWarning("no data buffer available");
     137             :   }
     138           0 :   fBlocks.clear();
     139           0 :   return fBlocks;
     140           0 : }
     141             : 
     142             : int AliHLTDumpTask::ReleaseDataBlocks()
     143             : {
     144             :   // see header file for class documentation
     145             :   int iResult=0;
     146           0 :   if (!fpDataBuffer) return 0;
     147             : 
     148           0 :   if (fBlocks.size()==0 && fpDataBuffer->GetNofPendingConsumers()>0) {
     149             :     // There are data blocks in the parents which this task has not yet
     150             :     // subscribed to. The subscription takes place in GetDataBlocks.
     151             :     // However, this method is not necessarily called.
     152             :     //
     153             :     // In order to switch buffer states correctly, first let the dummy
     154             :     // task as the only consumer subscribe to all those buffers and
     155             :     // release them further down. Basically, the buffers are arranged
     156             :     // in a different internal list, which is the only state they can be
     157             :     // released from. This approach has been chosen to implement the
     158             :     // DumpTask having no real consumers but at the same time has to
     159             :     // behave like a normal task in AliHLTTask::ProcessTask
     160           0 :     fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlocks);
     161           0 :   }
     162             : 
     163           0 :   for (unsigned int i=0; i<fBlocks.size(); i++) {
     164           0 :     fpDataBuffer->Release(&(fBlocks[i]), fpDummyTask->GetComponent(), this);
     165             :   }
     166           0 :   fBlocks.clear();
     167           0 :   return iResult;
     168           0 : }

Generated by: LCOV version 1.11