]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- HLTOUT: added support for sub collections
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Jun 2008 12:18:42 +0000 (12:18 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Jun 2008 12:18:42 +0000 (12:18 +0000)
- HLTOUT: added support for multiple block selection
- HLTSystem: started implementation of kChain handlers (not yet functional)

HLT/BASE/AliHLTOUT.cxx
HLT/BASE/AliHLTOUT.h
HLT/BASE/AliHLTOUTHandler.h
HLT/BASE/AliHLTOUTHomerBuffer.cxx
HLT/BASE/AliHLTSystem.cxx
HLT/BASE/AliHLTSystem.h
HLT/rec/AliRawReaderHLT.cxx

index a92561684db9843fc4248cc77412d6bc1c5a21d9..4d2f4987e387189dfd48d9fb16e1cbebbff830b2 100644 (file)
@@ -1,31 +1,26 @@
 // $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.                  *
- **************************************************************************/
+//**************************************************************************
+//* 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   AliHLTOUT.cxx
     @author Matthias Richter
     @date   
-    @brief  The control class for HLTOUT data.                            */
-
-// see header file for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+    @brief  The control class for HLTOUT data.
+*/
 
 #include <cerrno>
 #include <cassert>
@@ -42,9 +37,9 @@ AliHLTOUT::AliHLTOUT()
   fSearchDataType(kAliHLTVoidDataType),
   fSearchSpecification(kAliHLTVoidDataSpec),
   fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
-  fFlags(0),
+  fFlags(kSkipProcessed),
   fBlockDescList(),
-  fCurrent(fBlockDescList.begin()),
+  fCurrent(0),
   fpBuffer(NULL),
   fDataHandlers(),
   fbVerbose(true)
@@ -59,6 +54,9 @@ AliHLTOUT::AliHLTOUT()
 AliHLTOUT::~AliHLTOUT()
 {
   // see header file for class documentation
+  if (CheckStatusFlag(kIsSubCollection)) {
+    HLTWarning("severe internal error: collection has not been released, potential crash due to invalid pointer");
+  }
 }
 
 int AliHLTOUT::Init()
@@ -81,22 +79,23 @@ int AliHLTOUT::GetNofDataBlocks()
 }
 
 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
-                                   AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
+                                   AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
+                                   bool skipProcessed)
 {
   // see header file for class documentation
-  if (CheckStatusFlag(kLocked)) return -EPERM;
-  fCurrent=fBlockDescList.begin();
+  fCurrent=0;
   fSearchDataType=dt;
   fSearchSpecification=spec;
   fSearchHandlerType=handlerType;
+  if (skipProcessed) SetStatusFlag(kSkipProcessed);
+  else ClearStatusFlag(kSkipProcessed);
   return FindAndSelectDataBlock();
 }
 
 int AliHLTOUT::SelectNextDataBlock()
 {
   // see header file for class documentation
-  if (CheckStatusFlag(kLocked)) return -EPERM;
-  if (fCurrent==fBlockDescList.end()) return -ENOENT;
+  if (fCurrent>=fBlockDescList.size()) return -ENOENT;
   fCurrent++;
   return FindAndSelectDataBlock();
 }
@@ -106,11 +105,13 @@ int AliHLTOUT::FindAndSelectDataBlock()
   // see header file for class documentation
   if (CheckStatusFlag(kLocked)) return -EPERM;
   int iResult=-ENOENT;
-  while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
-    if ((*fCurrent)==fSearchDataType &&
-       (fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) &&
-       (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent->GetIndex())==fSearchHandlerType)) {
-      iResult=fCurrent->GetIndex();
+  while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
+    if (fBlockDescList[fCurrent]==fSearchDataType &&
+       (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
+       (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fBlockDescList[fCurrent].GetIndex())==fSearchHandlerType) &&
+       (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
+       (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
+      iResult=fBlockDescList[fCurrent].GetIndex();
       // TODO: check the byte order on the current system and the byte order of the
       // data block, print warning when mismatch and user did not check
       //AliHLTOUTByteOrder blockBO=CheckByteOrder();
@@ -138,10 +139,10 @@ int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32
 {
   // see header file for class documentation
   int iResult=-ENOENT;
-  if (fCurrent!=fBlockDescList.end()) {
+  if (fCurrent<fBlockDescList.size()) {
     iResult=0;
-    dt=(*fCurrent);
-    spec=(*fCurrent);
+    dt=fBlockDescList[fCurrent];
+    spec=fBlockDescList[fCurrent];
   }
   return iResult;
 }
@@ -163,8 +164,8 @@ AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
 {
   // see header file for class documentation
-  if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
-  return fCurrent->GetIndex();
+  if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
+  return fBlockDescList[fCurrent].GetIndex();
 }
 
 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
@@ -173,8 +174,8 @@ int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size
   int iResult=-ENOENT;
   pBuffer=NULL;
   size=0;
-  if (fCurrent!=fBlockDescList.end()) {
-    if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
+  if (fCurrent<fBlockDescList.size()) {
+    if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(pBuffer, size))>=0) {
       fpBuffer=pBuffer;
     }
   }
@@ -228,9 +229,9 @@ int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
 {
   // see header file for class documentation
-  if (fCurrent!=fBlockDescList.end()) {
+  if (fCurrent<fBlockDescList.size()) {
     SetStatusFlag(kByteOrderChecked);
-    AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
+    AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
     return order;
   }
   return kInvalidByteOrder;
@@ -239,9 +240,9 @@ AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
 {
   // see header file for class documentation
-  if (fCurrent!=fBlockDescList.end()) {
+  if (fCurrent<fBlockDescList.size()) {
     SetStatusFlag(kAlignmentChecked);
-    int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
+    int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
     return alignment;
   }
   return -ENOENT;
@@ -428,12 +429,12 @@ void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
   fBlocks.push_back(index);
 }
 
-bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
+bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const
 {
   // see header file for class documentation
   AliHLTOUTIndexList::iterator element;
-  for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
-    if (*element==index) return true;
+  for (unsigned int i=0; i<fBlocks.size(); i++) {
+    if (fBlocks[i]==index) return true;
   }
   return false;
 }
@@ -552,3 +553,126 @@ void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
   assert(0);
   HLTFatal("severe internal error: class mismatch");
 }
+
+int AliHLTOUT::SelectDataBlock()
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (fCurrent>=fBlockDescList.size()) return 0;
+  fBlockDescList[fCurrent].Select(true);
+  EnableBlockSelection();
+  return iResult;
+}
+
+int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pHandlerDesc) return 0;
+
+  AliHLTOUTBlockDescriptorVector::iterator element;
+  for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+       block!=fBlockDescList.end();
+       block++) {
+    if (pHandlerDesc->HasIndex(block->GetIndex()))
+      block->Select(true);
+    else
+      block->Select(false);
+  }
+  EnableBlockSelection();
+  
+  return iResult;
+}
+
+int AliHLTOUT::EnableBlockSelection()
+{
+  // see header file for class documentation
+  SetStatusFlag(kBlockSelection);
+  return 0;
+}
+
+int AliHLTOUT::DisableBlockSelection()
+{
+  // see header file for class documentation
+  ClearStatusFlag(kBlockSelection);
+  return 0;
+}
+
+int AliHLTOUT::ResetBlockSelection()
+{
+  // see header file for class documentation
+  for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+       block!=fBlockDescList.end();
+       block++) {
+    block->Select(false);
+  }
+  return 0;
+}
+
+int AliHLTOUT::MarkDataBlockProcessed()
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (fCurrent>=fBlockDescList.size()) return 0;
+  fBlockDescList[fCurrent].MarkProcessed();
+  return iResult;
+}
+
+int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pHandlerDesc) return 0;
+
+  AliHLTOUTBlockDescriptorVector::iterator element;
+  for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+       block!=fBlockDescList.end();
+       block++) {
+    if (pHandlerDesc->HasIndex(block->GetIndex()))
+      block->MarkProcessed();
+  }
+  
+  return iResult;
+}
+
+int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pCollection) return 0;
+
+  int index=-1;
+  for (index=pCollection->SelectFirstDataBlock();
+       index>=0;
+       index=pCollection->SelectNextDataBlock()) {
+    AliHLTComponentDataType dt=kAliHLTVoidDataType;
+    AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+    pCollection->GetDataBlockDescription(dt, spec);  
+    AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
+    AddBlockDescriptor(desc);
+    iResult++;
+  }
+  if (iResult>0) {
+    pCollection->SetStatusFlag(kIsSubCollection);
+  }
+
+  return iResult;
+}
+
+int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pCollection) return 0;
+
+  AliHLTOUTBlockDescriptorVector::iterator element;
+  for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
+       block!=fBlockDescList.end();
+       block++) {
+    if ((*block)==pCollection) {
+      element=fBlockDescList.erase(element);
+    }
+  }
+
+  return iResult;
+}
index 82c338cce73c616ce30d46ac92e2eb552b18882e..7798cc727d6f41a2d50fb007490067a3f9b8aa08 100644 (file)
@@ -138,23 +138,50 @@ class AliHLTOUT : public AliHLTLogging {
    */
   class AliHLTOUTBlockDescriptor {
   public:
-    AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index)
-      : fDataType(dt), fSpecification(spec), fIndex(index) {};
+    AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index, AliHLTOUT* pCollection)
+      : fDataType(dt), fSpecification(spec), fIndex(index), fSelected(false), fProcessed(false), fpCollection(pCollection) {};
+    AliHLTOUTBlockDescriptor(const AliHLTOUTBlockDescriptor& src)
+      : fDataType(src.fDataType), fSpecification(src.fSpecification), fIndex(src.fIndex), fSelected(false), fProcessed(false), fpCollection(src.fpCollection) {}
+    AliHLTOUTBlockDescriptor& operator=(const AliHLTOUTBlockDescriptor& src)
+    { fDataType=src.fDataType; fSpecification=src.fSpecification; fIndex=src.fIndex; fSelected=false; fProcessed=false; fpCollection=src.fpCollection; return *this; }
     ~AliHLTOUTBlockDescriptor() {}
 
     operator AliHLTComponentDataType() const {return fDataType;}
     operator AliHLTUInt32_t() const {return fSpecification;}
     int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
     int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
+    int operator==(AliHLTOUT* collection) const {return collection==fpCollection;}
 
     AliHLTUInt32_t GetIndex() const {return fIndex;}
-  private:
+
+    bool IsSelected() const {return fSelected;}
+    void Select(bool selected=true) {fSelected=selected;}
+    bool IsProcessed() const {return fSelected;}
+    void MarkProcessed() {fProcessed=true;}
+
+    /**
+     * Get the data buffer
+     * @param pBuffer [out] buffer of the selected data block
+     * @param size    [out] size of the selected data block
+     */
+    int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size) {
+      if (fpCollection) return fpCollection->GetDataBuffer(GetIndex(), pBuffer, size);
+      return -ENODEV;
+    }
+
+  private:      
     /** data type of the block */
     AliHLTComponentDataType fDataType; //!transient
     /** data specification of the block */
     AliHLTUInt32_t          fSpecification; //!transient
     /** index in the data stream */
     AliHLTUInt32_t          fIndex; //!transient
+    /** selection flag */
+    bool                    fSelected; //!transient
+    /** processed flag */
+    bool                    fProcessed; //!transient
+    /** the collection */
+    AliHLTOUT*              fpCollection; //!transient
   };
 
   class AliHLTOUTHandlerListEntry {
@@ -211,7 +238,7 @@ class AliHLTOUT : public AliHLTLogging {
      * Check if an index is served by this descriptor.
      * @return true if the index is in the table
      */
-    bool HasIndex(AliHLTUInt32_t index);
+    bool HasIndex(AliHLTUInt32_t index) const;
 
   private:
     /** standard constructor prohibited */
@@ -232,6 +259,35 @@ class AliHLTOUT : public AliHLTLogging {
 
   typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
   typedef vector<AliHLTOUTBlockDescriptor>  AliHLTOUTBlockDescriptorVector;
+  typedef vector<AliHLTOUT*>                AliHLTOUTPVector;
+
+  /**
+   * Selection guard for the AliHLTOUT object.
+   * If the object is locked, the selection of data blocks can not be changed.
+   */
+  class AliHLTOUTSelectionGuard {
+  public:
+    /** constructor */
+    AliHLTOUTSelectionGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
+    {if (fpInstance) fpInstance->SelectDataBlock();}
+    /** constructor */
+    AliHLTOUTSelectionGuard(AliHLTOUT* pInstance, const AliHLTOUTHandlerListEntry* pHandlerDesc) : fpInstance(pInstance)
+    {if (fpInstance) fpInstance->SelectDataBlocks(pHandlerDesc);}
+    /** destructor */
+    ~AliHLTOUTSelectionGuard()
+    {if (fpInstance) fpInstance->DisableBlockSelection();}
+
+  private:
+    /** standard constructor prohibited */
+    AliHLTOUTSelectionGuard();
+    /** copy constructor prohibited */
+    AliHLTOUTSelectionGuard(const AliHLTOUTSelectionGuard&);
+    /** assignment operator prohibited */
+    AliHLTOUTSelectionGuard& operator=(const AliHLTOUTSelectionGuard&);
+
+    /** the AliHLTOUT instance the guard is locking */
+    AliHLTOUT* fpInstance; //!transient
+  };
 
   /**
    * Init for processing.
@@ -261,7 +317,8 @@ class AliHLTOUT : public AliHLTLogging {
    */
   int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
                           AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
-                          AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
+                          AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput,
+                          bool skipProcessed=true);
 
   /**
    * Select the next data block of data type and specification of the previous
@@ -309,6 +366,54 @@ class AliHLTOUT : public AliHLTLogging {
    */
   int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
 
+  /**
+   * Add the current data block to the selection.
+   * Note: enables also the block selection
+   */
+  int SelectDataBlock();
+
+  /**
+   * Add the all data blocks of a certain handler to the selection.
+   * Note: enables also the block selection
+   */
+  int SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc);
+
+  /**
+   * Enable the selection of data blocks.
+   */
+  int EnableBlockSelection();
+
+  /**
+   * Disable the selection of data blocks.
+   */
+  int DisableBlockSelection();
+
+  /**
+   * Reset the data block selection.
+   * Resets the selection list, none of the blocks is selected.
+   */
+  int ResetBlockSelection();
+
+  /**
+   * Mark the current block as processed.
+   */
+  int MarkDataBlockProcessed();
+
+  /**
+   * Mark all data blocks of a certain handler processed.
+   */
+  int MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc);
+
+  /**
+   * Add a sub collection to the HLTOUT.
+   */
+  int AddSubCollection(AliHLTOUT* pCollection);
+
+  /**
+   * Release a previously added sub collection.
+   */
+  int ReleaseSubCollection(AliHLTOUT* pCollection);
+
   /**
    * Get module agent for the selected data block.
    */
@@ -415,7 +520,7 @@ class AliHLTOUT : public AliHLTLogging {
    * Internal status flags
    */
   enum {
-    /** the HLTOUT object is locked with the current data block */
+    /** the HLTOUT object is locked with the current data block selection */
     kLocked = 0x1,
     /** childs can add block descriptors */
     kCollecting = 0x2,
@@ -426,7 +531,13 @@ class AliHLTOUT : public AliHLTLogging {
     /** user of the data block has checked the alignment */
     kAlignmentChecked = 0x10,
     /** warning on alignment missmatch has been printed */
-    kAlignmentWarning = 0x20
+    kAlignmentWarning = 0x20,
+    /** enable block selection list */
+    kBlockSelection = 0x40,
+    /** skip processed data blocks */
+    kSkipProcessed = 0x80,
+    /** marked as sub collection */
+    kIsSubCollection = 0x100
   };
 
   /**
@@ -465,7 +576,11 @@ class AliHLTOUT : public AliHLTLogging {
    * Select the data block of data type and specification of the previous
    * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
    * and @ref SelectNextDataBlock, starts to find a block at the current list
-   * position. 
+   * position.
+   * 
+   * The data block is searched from the conditions of fSearchDataType,
+   * fSearchSpecification, fSearchHandlerType and the selection list.
+   *
    * @return identifier >=0 if success, neg. error code if failed         <br>
    *                        -ENOENT if no block found                     <br>
    *                        -EPERM if access denied (object locked)
@@ -535,7 +650,7 @@ class AliHLTOUT : public AliHLTLogging {
   AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
 
   /** current position in the list */
-  AliHLTOUTBlockDescriptorVector::iterator fCurrent; //!transient
+  unsigned int fCurrent; //!transient
 
   /** data buffer under processing */
   const AliHLTUInt8_t* fpBuffer; //!transient
@@ -546,6 +661,6 @@ class AliHLTOUT : public AliHLTLogging {
   /** verbose or silent output */
   bool fbVerbose; //!transient
 
-  ClassDef(AliHLTOUT, 2)
+  ClassDef(AliHLTOUT, 3)
 };
 #endif
index 90c5edc23b6318be8546e8f9ce9fc00a2c8b767f..88fead8b452069ab7b7974dd8513a7915d805611 100644 (file)
@@ -40,7 +40,10 @@ class AliHLTOUTHandler : public AliHLTLogging {
 
   /**
    * Process the data.
-   * The data and it's properties can be retrieved by the following member
+   * The data blocks can be selected by AliHLTOUT::SelectFirstDataBlock() and
+   * AliHLTOUT::SelectNextDataBlock()
+   *
+   * Properties of the current data block can be retrieved by the following member
    * functions of AliHLTOUT:
    * - AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
    * - AliHLTOUT::GetDataBlockIndex()
index 789d5006ec06c02c840d6680fd5878cd0c4d7d1f..a2d1fc75ebf0cf7271fdc4c452cb3eef870b0c22 100644 (file)
@@ -143,7 +143,7 @@ int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt
       homer_uint32 spec=pReader->GetBlockDataSpec( i );
       AliHLTComponentDataType dt;
       AliHLTComponent::SetDataType(dt, ByteSwap64(id), ByteSwap32(origin));
-      AliHLTOUTBlockDescriptor desc(dt, spec, offset|i);
+      AliHLTOUTBlockDescriptor desc(dt, spec, offset|i, this);
       HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(dt).c_str(), spec);
       iResult=AddBlockDescriptor(desc);
     }
index e48c89f1f6878a1e7e9be313a28f6dfe1f32ca06..8e0ea0d4918f1d9f35bb7aff708539bb851d90b2 100644 (file)
@@ -732,8 +732,16 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
   // see header file for class documentation
   int iResult=0;
   if (!pHLTOUT) return -EINVAL;
-
   HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
+
+  //
+  // process all kChain handlers first
+  //
+  if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
+    HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
+    iResult=0;
+  } 
+
   AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
 
   // first come first serve: the ESD of the first handler is also filled into
@@ -751,6 +759,8 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
     pHLTOUT->GetDataBlockDescription(dt, spec);
     AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
     AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
+
+    // default handling for ESD data blocks does not require an explicite handler
     if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
       handlerType=AliHLTModuleAgent::kEsd;
     }
@@ -759,9 +769,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
     case AliHLTModuleAgent::kEsd:
       {
        if (pHandler) {
-         // preprocess and write later
-         AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
-         pHandler->ProcessData(pHLTOUT);
+         // schedule for later processing
          pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
        } else {
          // write directly
@@ -775,6 +783,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
            }
            pHLTOUT->ReleaseDataBuffer(pBuffer);
          }
+         pHLTOUT->MarkDataBlockProcessed();
        }
       }
       break;
@@ -787,7 +796,8 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
                 AliHLTComponent::DataType2Text(dt).c_str(), spec);
       break;
     case AliHLTModuleAgent::kChain:
-      HLTWarning("HLTOUT handler type 'kChain' not yet implemented: agent %s, data type %s, specification %#x",
+      HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
+                "New block of this type added by the chain? Skipping data block ...",
                 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
                 AliHLTComponent::DataType2Text(dt).c_str(), spec);
       break;
@@ -821,9 +831,11 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
   AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
   // write all postponed esd data blocks
   for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
+    AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*esdHandler));         
     AliHLTOUTHandler* pHandler=*esdHandler;
     const AliHLTUInt8_t* pBuffer=NULL;
     AliHLTUInt32_t size=0;
+    pHandler->ProcessData(pHLTOUT);
     if ((size=pHandler->GetProcessedData(pBuffer))>0) {
       AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
       AliHLTComponentDataType dt=desc;
@@ -834,6 +846,56 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
       }
       pHandler->ReleaseProcessedData(pBuffer, size);
     }
+    pHLTOUT->MarkDataBlocksProcessed(&(*esdHandler));
+  }
+
+  return iResult;
+}
+
+int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pHLTOUT) return -EINVAL;
+
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector chainHandlers;
+  for (iResult=pHLTOUT->SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, AliHLTModuleAgent::kUnknownOutput);
+       iResult>=0;
+       iResult=pHLTOUT->SelectNextDataBlock()) {
+    AliHLTComponentDataType dt=kAliHLTVoidDataType;
+    AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+    pHLTOUT->GetDataBlockDescription(dt, spec);
+    AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
+    AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
+    if (handlerType==AliHLTModuleAgent::kChain) {
+      if (!pHandler) {
+       HLTWarning("missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block",
+                  pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                  AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      } else {
+       pHLTOUT->InsertHandler(chainHandlers, pHLTOUT->GetDataBlockHandlerDesc());
+      }
+    }
+  }
+  // TODO: the return value of SelectFirst/NextDataBlock must be
+  // changed in order to avoid this check
+  if (iResult==-ENOENT) iResult=0;
+
+  // process all defined chain handlers
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
+  for (chainHandler=chainHandlers.begin(); chainHandler!=chainHandlers.end() && iResult>=0; chainHandler++) {
+    AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));       
+    AliHLTOUTHandler* pHandler=*chainHandler;
+    const AliHLTUInt8_t* pBuffer=NULL;
+    AliHLTUInt32_t size=0;
+    pHandler->ProcessData(pHLTOUT);
+    if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+      AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
+      AliHLTComponentDataType dt=desc;
+
+      pHandler->ReleaseProcessedData(pBuffer, size);
+    }
+    pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
   }
 
   return iResult;
index 70e17196926ecdbf1701a36b03237507d7f7c49f..3bded3cd1ebbb34532b0833019182c5cac3e02f0 100644 (file)
@@ -292,6 +292,13 @@ class AliHLTSystem : public AliHLTLogging {
    */
   int ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd);
 
+  /**
+   * Process all kChain-type data blocks of the HLTOUT data.
+   * The function is involed from ProcessHLTOUT as the first step in
+   * the processing.
+   */
+  int ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT);
+
   /**
    * Load component libraries.
    * @param libs          string of blank separated library names
index 827b82d27d8c4f51963874624c528552c394535a..51f5d1c75f4b84d6f859fd0b6512a0bbf71f62f0 100644 (file)
@@ -486,7 +486,7 @@ Bool_t   AliRawReaderHLT::ReadNextHLTData()
     AliHLTOUTHandler* pHandler=fpHLTOUT->GetHandler();
     if (pHandler) {
       if (dynamic_cast<AliHLTOUTHandlerEquId*>(pHandler)!=NULL) {
-       AliHLTOUT::AliHLTOUTLockGuard g(fpHLTOUT);
+       AliHLTOUT::AliHLTOUTSelectionGuard g(fpHLTOUT);
        fEquipmentId=pHandler->ProcessData(fpHLTOUT);
        fpData=NULL;
        fDataSize=pHandler->GetProcessedData(fpData);