]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
moving functionality into a separate base class for buffer sink tasks. In preparation...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 24 Oct 2008 11:31:04 +0000 (11:31 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 24 Oct 2008 11:31:04 +0000 (11:31 +0000)
HLT/BASE/AliHLTDumpTask.cxx [new file with mode: 0644]
HLT/BASE/AliHLTDumpTask.h [new file with mode: 0644]
HLT/BASE/AliHLTOUTTask.cxx
HLT/BASE/AliHLTOUTTask.h
HLT/libHLTbase.pkg

diff --git a/HLT/BASE/AliHLTDumpTask.cxx b/HLT/BASE/AliHLTDumpTask.cxx
new file mode 100644 (file)
index 0000000..36c0ad1
--- /dev/null
@@ -0,0 +1,157 @@
+// $Id$
+
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* Permission to use, copy, modify and distribute this software and its   *
+//* documentation strictly for non-commercial purposes is hereby granted   *
+//* without fee, provided that the above copyright notice appears in all   *
+//* copies and that both the copyright notice and this permission notice   *
+//* appear in the supporting documentation. The authors make no claims     *
+//* about the suitability of this software for any purpose. It is          *
+//* provided "as is" without express or implied warranty.                  *
+//**************************************************************************
+
+/** @file   AliHLTDumpTask.cxx
+    @author Matthias Richter
+    @date   
+    @brief  Base class for data sinks with direct buffer access.
+*/
+
+#include "AliHLTDumpTask.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTDumpTask)
+
+AliHLTDumpTask::AliHLTDumpTask(const char* chains)
+  :
+  AliHLTTask(),
+  fpDummyTask(NULL),
+  fpDummyConfiguration(NULL),
+  fBlocks()
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  if (chains && chains[0]!=0) SetChains(chains);
+}
+
+AliHLTDumpTask::~AliHLTDumpTask()
+{
+  // see header file for class documentation
+
+  // UnsetTarget called automatically
+  if (fpDummyTask) delete fpDummyTask;
+  fpDummyTask=NULL;
+
+  if (fpDummyConfiguration) delete fpDummyConfiguration;
+  fpDummyConfiguration=NULL;
+
+  if (fpConfiguration) delete fpConfiguration;
+  fpConfiguration=NULL;
+}
+
+int AliHLTDumpTask::SetChains(const char* chains)
+{
+  // see header file for class documentation
+  if (!chains || chains[0]==0) {
+    HLTError("invalid chain id string");
+    return -EINVAL;
+  }
+  TString taskname=chains;
+  taskname.ReplaceAll(" ", "_");
+  taskname+="_hltDumpTask";
+
+  // This is just a trick to use the existing Task handling, especially the
+  // ProcessTask function.
+  // 1. The 'BlockFilter' just forwards the data blocks of all specified chains
+  // 2. A dummy task is added to the target list in order to set the data segments
+  //    after forwarding. In case of an empty target list the data is just discarded.
+  // That's maybe not the most elegant solution but far less awkward as one would
+  // expect.
+  fpConfiguration=new AliHLTConfiguration(taskname.Data(), "BlockFilter", chains, NULL);
+  TString dummyname=chains;
+  dummyname.ReplaceAll(" ", "_");
+  dummyname+="_never_used_dummy_";
+  fpDummyConfiguration=new AliHLTConfiguration(dummyname.Data(), "BlockFilter", taskname.Data(), NULL);
+  if (fpDummyConfiguration) {
+    fpDummyTask=new AliHLTTask(fpDummyConfiguration);
+    SetTarget(fpDummyTask);
+  }
+  return 0;
+}
+
+int AliHLTDumpTask::CustomInit(AliHLTComponentHandler* pCH)
+{
+  // see header file for class documentation
+  if (!fpDummyTask) return -ENOENT;
+  return fpDummyTask->Init(NULL, pCH);
+}
+
+int AliHLTDumpTask::CustomCleanup()
+{
+  // see header file for class documentation
+  if (!fpDummyTask) return -ENOENT;
+  return fpDummyTask->Deinit();
+}
+
+const char* AliHLTDumpTask::GetSourceChains() const
+{
+  // see header file for class documentation
+  if (!fpConfiguration) return "";
+  return fpConfiguration->GetSourceSettings();
+}
+
+const AliHLTComponentBlockDataList& AliHLTDumpTask::GetDataBlocks()
+{
+  // see header file for class documentation
+  if (fBlocks.size()>0) return fBlocks;
+  if (fpDataBuffer) {
+    if (!fpDataBuffer->FindConsumer(fpDummyTask->GetComponent())) {
+      // in order to subscribe to the buffers the dummy consumer
+      // needs to be set. The dummy task is not in the AliHLTSystem chain
+      // and therefor not automatically set.
+      fpDataBuffer->SetConsumer(fpDummyTask->GetComponent());
+    }
+    fBlocks.clear();
+    if (fpDataBuffer->GetNofSegments()>0 
+       && fpDataBuffer->FindConsumer(fpDummyTask->GetComponent(), 0 /*search only among pending consumers*/)>0) {
+      if (fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlocks)>=0) {
+       return fBlocks;
+      } else {
+       HLTError("failed to subscribe to data buffer");
+      }
+    }
+  } else {
+    // 2008-08-07 this is not a failure condition
+    // If the chain has not been processed because LocalReconstruction
+    // is not enabled, the task will be empty
+    //HLTWarning("no data buffer available");
+  }
+  fBlocks.clear();
+  return fBlocks;
+}
+
+int AliHLTDumpTask::ReleaseDataBlocks()
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!fpDataBuffer) return 0;
+
+  if (fBlocks.size()==0 && fpDataBuffer->GetNofPendingConsumers()>0) {
+    // not yet subscribed
+    fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlocks);
+  }
+
+  for (unsigned int i=0; i<fBlocks.size(); i++) {
+    fpDataBuffer->Release(&(fBlocks[i]), fpDummyTask->GetComponent(), this);
+  }
+  fBlocks.clear();
+  return iResult;
+}
diff --git a/HLT/BASE/AliHLTDumpTask.h b/HLT/BASE/AliHLTDumpTask.h
new file mode 100644 (file)
index 0000000..cdb2674
--- /dev/null
@@ -0,0 +1,88 @@
+//-*- Mode: C++ -*-
+// $Id$
+#ifndef ALIHLTDUMPTASK_H
+#define ALIHLTDUMPTASK_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+/** @file   AliHLTDumpTask.h
+    @author Matthias Richter
+    @date   
+    @brief  Base class for data sinks with direct buffer access.
+*/
+
+#include "AliHLTOUT.h"
+#include "AliHLTTask.h"
+
+/**
+ * @class AliHLTDumpTask
+ * A base class for data sinks without a processing component. Tasks of this
+ * type can be added at the end of the processing chain and allow direct
+ * access to the data blocks produced by the last components of the chain.
+ * 
+ * The constructor takes the chains as a blank separated list of chain ids.
+ *
+ * @ingroup alihlt_system
+ */
+class AliHLTDumpTask : public AliHLTTask {
+ public:
+  /** constructor */
+  AliHLTDumpTask(const char* chains=NULL);
+  /** standard destructor */
+  virtual ~AliHLTDumpTask();
+
+  /**
+   * Set the parent reconstruction chains this task is going to subscribe to.
+   * @param chains    blank separated list of chain ids
+   */
+  int SetChains(const char* chains);
+
+  /**
+   * Get string of the source chains.
+   */
+  const char* GetSourceChains() const;
+
+  /**
+   * Get the list of data blocks.
+   * Subscribe to the publishers if not yet done and return pointer
+   * to block list.
+   */
+  const AliHLTComponentBlockDataList& GetDataBlocks();
+
+  /**
+   * Explicitly release data blocks.
+   */
+  int ReleaseDataBlocks();
+
+ protected:
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTDumpTask(const AliHLTDumpTask&);
+  /** assignment operator prohibited */
+  AliHLTDumpTask& operator=(const AliHLTDumpTask&);
+
+  /**
+   * Custom initialization for child tasks.
+   * Create and init the dummy task.
+   */
+  int CustomInit(AliHLTComponentHandler* pCH);
+
+  /**
+   * Custom clean up for child tasks.
+   */
+  int CustomCleanup();
+
+  /** a dummy task to pretend existence of a consumer */
+  AliHLTTask* fpDummyTask; //!transient
+
+  /** the configuration for the dummy task */
+  AliHLTConfiguration* fpDummyConfiguration; //!transient
+
+  /** list of block descriptors of the output */
+  AliHLTComponentBlockDataList fBlocks;
+
+  ClassDef(AliHLTDumpTask, 0)
+};
+#endif
index b55349c230a274faece44129c5928f926d4ef5f9..d888663d52dc5a4dcdacd02fc3cd2ec0486cef86 100644 (file)
@@ -30,95 +30,29 @@ ClassImp(AliHLTOUTTask)
 AliHLTOUTTask::AliHLTOUTTask(const char* chains)
   :
   AliHLTOUT(),
-  AliHLTTask(),
-  fpDummyTask(NULL),
-  fpDummyConfiguration(NULL),
-  fBlockDescList()
+  AliHLTDumpTask(chains)
 { 
   // see header file for class documentation
   // or
   // refer to README to build package
   // or
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
-  TString taskname=chains;
-  taskname.ReplaceAll(" ", "_");
-  taskname+="_hltouttask";
-
-  // This is just a trick to use the existing Task handling, especially the
-  // ProcessTask function.
-  // 1. The 'BlockFilter' just forwards the data blocks of all specified chains
-  // 2. A dummy task is added to the target list in order to set the data segments
-  //    after forwarding. In case of an empty target list the data is just discarded.
-  // That's maybe not the most elegant solution but far less awkward as one would
-  // expect.
-  fpConfiguration=new AliHLTConfiguration(taskname.Data(), "BlockFilter", chains, NULL);
-  TString dummyname=chains;
-  dummyname.ReplaceAll(" ", "_");
-  dummyname+="_never_used_dummy_";
-  fpDummyConfiguration=new AliHLTConfiguration(dummyname.Data(), "BlockFilter", taskname.Data(), NULL);
-  if (fpDummyConfiguration) {
-    fpDummyTask=new AliHLTTask(fpDummyConfiguration);
-    SetTarget(fpDummyTask);
-  }
 }
 
 AliHLTOUTTask::~AliHLTOUTTask()
 {
   // see header file for class documentation
-
-  // UnsetTarget called automatically
-  if (fpDummyTask) delete fpDummyTask;
-  fpDummyTask=NULL;
-
-  if (fpDummyConfiguration) delete fpDummyConfiguration;
-  fpDummyConfiguration=NULL;
-
-  if (fpConfiguration) delete fpConfiguration;
-  fpConfiguration=NULL;
-}
-
-int AliHLTOUTTask::CustomInit(AliHLTComponentHandler* pCH)
-{
-  // see header file for class documentation
-  if (!fpDummyTask) return -ENOENT;
-  return fpDummyTask->Init(NULL, pCH);
-}
-
-int AliHLTOUTTask::CustomCleanup()
-{
-  // see header file for class documentation
-  if (!fpDummyTask) return -ENOENT;
-  return fpDummyTask->Deinit();
 }
 
 int AliHLTOUTTask::GenerateIndex()
 {
   // see header file for class documentation
   int iResult=0;
-  if (fpDataBuffer) {
-    if (!fpDataBuffer->FindConsumer(fpDummyTask->GetComponent())) {
-      // in order to subscribe to the buffers the dummy consumer
-      // needs to be set. The dummy task is not in the AliHLTSystem chain
-      // and therefor not automatically set.
-      fpDataBuffer->SetConsumer(fpDummyTask->GetComponent());
-    }
-    fBlockDescList.clear();
-    if (fpDataBuffer->GetNofSegments()>0) {
-      if ((iResult=fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlockDescList))>=0) {
-       for (unsigned int i=0; i<fBlockDescList.size(); i++) {
-         AliHLTOUTBlockDescriptor desc(fBlockDescList[i].fDataType, fBlockDescList[i].fSpecification, i, this);
-         //HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(fBlockDescList[i].fDataType).c_str(), fBlockDescList[i].fSpecification);
-         iResult=AddBlockDescriptor(desc);
-       }
-      } else {
-       HLTError("failed to subscribe to data buffer");
-      }
-    }
-  } else {
-    // 2008-08-07 this is not a failure condition
-    // If the chain has not been processed because LocalReconstruction
-    // is not enabled, the task will be empty
-    //HLTWarning("no data buffer available");
+  const AliHLTComponentBlockDataList& list=GetDataBlocks();
+  for (unsigned int i=0; i<list.size(); i++) {
+    AliHLTOUTBlockDescriptor desc(list[i].fDataType, list[i].fSpecification, i, this);
+    //HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(list[i].fDataType).c_str(), list[i].fSpecification);
+    iResult=AddBlockDescriptor(desc);
   }
   return iResult;
 }
@@ -128,9 +62,10 @@ int AliHLTOUTTask::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBu
 {
   // see header file for class documentation
   int iResult=0;
-  if (index>=fBlockDescList.size()) return -ENOENT;
-  pBuffer=reinterpret_cast<AliHLTUInt8_t*>(fBlockDescList[index].fPtr);
-  size=fBlockDescList[index].fSize;
+  const AliHLTComponentBlockDataList& list=GetDataBlocks();
+  if (index>=list.size()) return -ENOENT;
+  pBuffer=reinterpret_cast<AliHLTUInt8_t*>(list[index].fPtr);
+  size=list[index].fSize;
   return iResult;
 }
 
@@ -150,24 +85,5 @@ int AliHLTOUTTask::CheckBlockAlignment(AliHLTUInt32_t /*index*/, AliHLTOUT::AliH
 int AliHLTOUTTask::ResetInput()
 {
   // see header file for class documentation
-  int iResult=0;
-  if (!fpDataBuffer) return 0;
-
-  if (fBlockDescList.size()==0 && fpDataBuffer->GetNofPendingConsumers()>0) {
-    // not yet subscribed
-    fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlockDescList);
-  }
-
-  for (unsigned int i=0; i<fBlockDescList.size(); i++) {
-    fpDataBuffer->Release(&(fBlockDescList[i]), fpDummyTask->GetComponent(), this);
-  }
-  fBlockDescList.clear();
-  return iResult;
-}
-
-const char* AliHLTOUTTask::GetSourceChains() const
-{
-  // see header file for class documentation
-  if (!fpConfiguration) return "";
-  return fpConfiguration->GetSourceSettings();
+  return ReleaseDataBlocks();
 }
index 0fe70e8a8b3a4103689a5e42f6761d6b74e2e7f0..2a57f6e171b1cea5c89743c5f5a099aa6ac592b4 100644 (file)
@@ -13,7 +13,7 @@
 */
 
 #include "AliHLTOUT.h"
-#include "AliHLTTask.h"
+#include "AliHLTDumpTask.h"
 
 /**
  * @class AliHLTOUTTask
  * an HLTOUT sub-collection.
  * 
  * The constructor takes the chains as a blank separated list of chain ids.
+ *
+ * @ingroup alihlt_system
  */
-class AliHLTOUTTask : public AliHLTOUT, public AliHLTTask {
+class AliHLTOUTTask : public AliHLTOUT, public AliHLTDumpTask {
  public:
   /** constructor */
   AliHLTOUTTask(const char* chains);
   /** standard destructor */
   virtual ~AliHLTOUTTask();
 
-  /**
-   * Get string of the source chains.
-   */
-  const char* GetSourceChains() const;
-
  protected:
 
  private:
@@ -45,17 +42,6 @@ class AliHLTOUTTask : public AliHLTOUT, public AliHLTTask {
   /** assignment operator prohibited */
   AliHLTOUTTask& operator=(const AliHLTOUTTask&);
 
-  /**
-   * Custom initialization for child tasks.
-   * Create and init the dummy task.
-   */
-  int CustomInit(AliHLTComponentHandler* pCH);
-
-  /**
-   * Custom clean up for child tasks.
-   */
-  int CustomCleanup();
-
   /**
    * Generate the index of the HLTOUT data.
    * Must be implemented by the child classes.
@@ -74,7 +60,7 @@ class AliHLTOUTTask : public AliHLTOUT, public AliHLTTask {
    * @param size    [out] size of the selected data block
    */
   int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
-                           AliHLTUInt32_t& size);
+                   AliHLTUInt32_t& size);
 
   /**
    * Check byte order of data block
@@ -86,15 +72,6 @@ class AliHLTOUTTask : public AliHLTOUT, public AliHLTTask {
    */
   int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type);
 
-  /** a dummy task to pretend existence of a consumer */
-  AliHLTTask* fpDummyTask; //!transient
-
-  /** the configuration for the dummy task */
-  AliHLTConfiguration* fpDummyConfiguration; //!transient
-
-  /** list of block descriptors of the output */
-  AliHLTComponentBlockDataList fBlockDescList;
-
-  ClassDef(AliHLTOUTTask, 0)
+  ClassDef(AliHLTOUTTask, 1)
 };
 #endif
index f03bd3764c29be33370b8246f17d5a19802701b7..62250ad2e63e0a0def16096174a1d582d3ac45b5 100644 (file)
@@ -12,6 +12,7 @@ CLASS_HDRS:=          AliHLTComponent.h \
                AliHLTConfiguration.h \
                AliHLTConfigurationHandler.h \
                AliHLTTask.h \
+               AliHLTDumpTask.h \
                AliHLTControlTask.h \
                AliHLTLogging.h \
                AliHLTDataBuffer.h \