]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- HLT simulation writes digit data in addition to raw data
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Apr 2008 00:54:41 +0000 (00:54 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Apr 2008 00:54:41 +0000 (00:54 +0000)
- bugfix AliHLTOUTComponent: wrong byte swap suppressed data origin in homer descriptor
- AliHLTEsdManager added: merging and writing of HLT ESDs
- HLTOUT treatment: AliHLTOUTHomerCollection abstract interface for digits/raw data added
- AliHLTOUTDigitReader added: reading of simulated HLT digit data
- AliHLTOUTRawReader: common functionality moved to AliHLTOUTHomerCollection
- TPCDigitPublisher enhanced: encode digits to raw data
- AltroData Generator: encoding on channel level
- corrections in documentation

36 files changed:
HLT/BASE/AliHLTComponent.cxx
HLT/BASE/AliHLTDataBuffer.cxx
HLT/BASE/AliHLTModuleAgent.cxx
HLT/BASE/AliHLTModuleAgent.h
HLT/BASE/AliHLTOUT.cxx
HLT/BASE/AliHLTOUT.h
HLT/BASE/AliHLTOUTHomerBuffer.cxx
HLT/BASE/AliHLTOfflineDataSink.h
HLT/BASE/AliHLTOfflineInterface.cxx
HLT/BASE/AliHLTSystem.cxx
HLT/BASE/AliHLTSystem.h
HLT/BASE/Makefile.am
HLT/BASE/interface/AliHLTExternalInterface.cxx
HLT/BASE/interface/AliHLTExternalInterface.h
HLT/RCU/AliHLTAltroGenerator.cxx
HLT/SampleLib/AliHLTSamplePreprocessor.h
HLT/TPCLib/AliHLTTPCEsdWriterComponent.cxx
HLT/TPCLib/AliHLTTPCFileHandler.cxx
HLT/TPCLib/AliHLTTPCFileHandler.h
HLT/TPCLib/macros/dumpTPCDigits.C [new file with mode: 0644]
HLT/TPCLib/macros/sim-hlt-tpc.C
HLT/libHLTrec.pkg
HLT/rec/AliHLTEsdManager.cxx [new file with mode: 0644]
HLT/rec/AliHLTEsdManager.h [new file with mode: 0644]
HLT/rec/AliHLTOUTDigitReader.cxx [new file with mode: 0644]
HLT/rec/AliHLTOUTDigitReader.h [new file with mode: 0644]
HLT/rec/AliHLTOUTHomerCollection.cxx [new file with mode: 0644]
HLT/rec/AliHLTOUTHomerCollection.h [new file with mode: 0644]
HLT/rec/AliHLTOUTRawReader.cxx
HLT/rec/AliHLTOUTRawReader.h
HLT/rec/AliHLTReconstructor.cxx
HLT/rec/AliHLTReconstructor.h
HLT/rec/Makefile.am
HLT/sim/AliHLTOUTComponent.cxx
HLT/sim/AliHLTOUTComponent.h
HLT/sim/AliHLTSimulation.cxx

index 9f68abb7a91e3c59730259991526a340875d84a1..ea786d1246ba33bb169f6d0f35e6d1035ba1b69d 100644 (file)
@@ -652,7 +652,7 @@ TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
          }
          //} else {
                } else if (bForce!=0) {
-         HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
+         HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
        }
       } else {
        HLTFatal("block descriptor empty");
@@ -1192,7 +1192,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
          AliHLTRunDesc rundesc;
          if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
            if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
-             HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
+             HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
            } else {
              HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
            }
@@ -1414,11 +1414,11 @@ int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigne
       if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
        AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
        if (fpInputBlocks[iBlockNo].fSize!=copy) {
-         HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
+         HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
          if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
        }
        if (copy!=iStructSize) {
-         HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
+         HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
          if (copy>iStructSize) {
            copy=iStructSize;
          } else {
index 1f2fe78140b49eb47fd9dc30655be934ec00d5d8..d784d856032ac6ef9d4b72706502d9cdc07b2716 100644 (file)
@@ -1,20 +1,20 @@
 // $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   AliHLTDataBuffer.cxx
     @author Matthias Richter
     @brief  Handling of Data Buffers for HLT components.
 */
 
-// 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 __GNUC__>= 3
 using namespace std;
 #endif
@@ -253,7 +247,7 @@ int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
     AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
     if (pDesc) {
       if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
-       HLTWarning("data segment missmatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
+       HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
        // TODO: appropriate error handling, but so far optional
        iResult=0;
       } else {
@@ -382,7 +376,7 @@ int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData*
        iResult=-EINVAL;
       }
     } else {
-      HLTFatal("internal data structur missmatch");
+      HLTFatal("internal data structur mismatch");
       iResult=-EFAULT;
     }
   } else {
index c9e8316a022b01c3cba7cac5160df871d42ac201..169878eb1878618e3d7b03696fcf96fbbc0e0ab0 100644 (file)
@@ -49,6 +49,8 @@ AliHLTModuleAgent::AliHLTModuleAgent(const char* id)
   Register(this);
 }
 
+const AliHLTModuleAgent::AliHLTOUTHandlerDesc AliHLTModuleAgent::fgkVoidHandlerDesc;
+
 AliHLTModuleAgent::~AliHLTModuleAgent()
 {
   // see header file for function documentation
index 0dedf769de26f4aab9f037f886be4d65d6bf1b1b..1d89054e0ff8832e9e6ef6551467d0b4b610f4e2 100644 (file)
@@ -272,6 +272,8 @@ class AliHLTModuleAgent : public TObject, public AliHLTLogging {
     bool operator==(const AliHLTOUTHandlerType handlerType) const {
       return fHType==handlerType;
     }
+    operator AliHLTOUTHandlerType() {return fHType;}
+    operator AliHLTComponentDataType() {return fDt;}
 
   private:
     /** type of the handler */
@@ -282,6 +284,8 @@ class AliHLTModuleAgent : public TObject, public AliHLTLogging {
     TString                 fModule;                         //!transient
   };
 
+  static const AliHLTOUTHandlerDesc fgkVoidHandlerDesc; //! initializer
+
   /**
    * Get handler description for a data block.
    * @param dt        [in] data type of the block
index 3cca730425595d81d566208b601492be64ea8e8a..26826b157a3e80375e337519c23635f6f3c90209 100644 (file)
@@ -109,7 +109,7 @@ int AliHLTOUT::FindAndSelectDataBlock()
        (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent->GetIndex())==fSearchHandlerType)) {
       iResult=fCurrent->GetIndex();
       // TODO: check the byte order on the current system and the byte order of the
-      // data block, print warning when missmatch and user did not check
+      // data block, print warning when mismatch and user did not check
       //AliHLTOUTByteOrder blockBO=CheckByteOrder();
       CheckByteOrder();
       /*
@@ -121,7 +121,7 @@ int AliHLTOUT::FindAndSelectDataBlock()
       ClearStatusFlag(kByteOrderChecked);
 
       // TODO: check the alignment on the current system and the alignment of the
-      // data block, print warning when missmatch and user did not check
+      // data block, print warning when mismatch and user did not check
       ClearStatusFlag(kAlignmentChecked);
 
       break;
@@ -143,6 +143,20 @@ int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32
   return iResult;
 }
 
+const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
+{
+  // see header file for class documentation
+  return FindHandlerDesc(GetDataBlockIndex());
+}
+
+AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
+{
+  // see header file for class documentation
+  AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(GetDataBlockIndex());
+  AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
+  return type;
+}
+
 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
 {
   // see header file for class documentation
@@ -176,6 +190,14 @@ int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
   return iResult;  
 }
 
+AliHLTModuleAgent* AliHLTOUT::GetAgent()
+{
+  // see header file for class documentation
+  AliHLTModuleAgent* pAgent=NULL;
+  pAgent=FindHandlerDesc(GetDataBlockIndex());
+  return pAgent;
+}
+
 AliHLTOUTHandler* AliHLTOUT::GetHandler()
 {
   // see header file for class documentation
@@ -184,6 +206,13 @@ AliHLTOUTHandler* AliHLTOUT::GetHandler()
   return pHandler;
 }
 
+int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
+{
+  // see header file for class documentation
+  HLTWarning("method not implemented in base class");
+  return -ENOSYS;
+}
+
 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
 {
   // see header file for class documentation
@@ -231,7 +260,7 @@ int AliHLTOUT::InitHandlers()
       AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
       if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
        AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
-       InsertHandler(entry);
+       InsertHandler(fDataHandlers, entry);
        remnants.pop_back();
        break;
       }
@@ -268,17 +297,17 @@ int AliHLTOUT::InitHandlers()
   return iResult;
 }
 
-int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
+int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
 {
   // see header file for class documentation
   int iResult=0;
-  AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
-  while (element!=fDataHandlers.end()) {
+  AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
+  while (element!=list.end()) {
     if (entry==(*element)) break;
     element++;
   }
-  if (element==fDataHandlers.end()) {
-    fDataHandlers.push_back(entry);
+  if (element==list.end()) {
+    list.push_back(entry);
   } else {
     element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
   }
index 23bc252bffdb6c3e3307593f2721f7d068462f79..2e923b6c3889af0120da982964cd656733b04bba 100644 (file)
@@ -19,6 +19,8 @@
 
 class AliHLTOUTHandler;
 class AliHLTOUTHandlerDesc; // AliHLTModuleAgent.h
+class AliESDEvent;
+class AliHLTReconstructor;
 
 #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
 
@@ -40,76 +42,6 @@ class AliHLTOUT : public AliHLTLogging {
   /** standard destructor */
   virtual ~AliHLTOUT();
 
-  /**
-   * Init for processing.
-   * The HLTOUT is scanned for all available data blocks and the
-   * AliHLTOUTHandler objects for the data blocks are created according
-   * to the module agents (see AliHLTModuleAgent).
-   */
-  int Init();
-
-  /**
-   * Get number of data blocks in the HLTOUT data
-   */
-  int GetNofDataBlocks();
-
-  /**
-   * Select the first data block of a certain data type and specification.
-   * The selection criteria can be of kAliHLTAnyDataType and/or
-   * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
-   *
-   * The search criteria can be combined with a handler type (e.g. kRawReader)
-   * @param dt    [in]  data type to match                                <br>
-   * @param spec  [in]  data specification to match                       <br>
-   * @param handlerType [in]  type of the handler
-   * @return identifier >0 if success, 0 if no block found                <br>
-   *         neg. error code if failed                                    <br>
-   *                        -EPERM if access denied (object locked)
-   */
-  int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
-                          AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
-                          AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
-
-  /**
-   * Select the next data block of data type and specification of the previous
-   * call to @ref SelectFirstDataBlock.
-   * @return identifier >0 if success, 0 if no block found                <br>
-   *         neg. error code if failed                                    <br>
-   *                        -EPERM if access denied (object locked)
-   */
-  int SelectNextDataBlock();
-
-  /**
-   * Get properties of the selected data block.
-   * @param dt    [out] data type of the selected block
-   * @param spec  [out] data specification of the selected block
-   */
-  int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
-
-  /**
-   * Get the index of the current data block.
-   * @return index, AliHLTOUTInvalidIndex if no block selected
-   */
-  AliHLTUInt32_t GetDataBlockIndex();
-
-  /**
-   * Get buffer of the selected data block.
-   * @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);
-
-  /**
-   * Release buffer after use.
-   * @param pBuffer [in]  buffer of the selected data block
-   */
-  int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
-
-  /**
-   * Get handler for the selected data block.
-   */
-  AliHLTOUTHandler* GetHandler();
-
   /**
    * Locking guard for the AliHLTOUT object.
    * If the object is locked, the selection of data blocks can not be changed.
@@ -199,6 +131,185 @@ class AliHLTOUT : public AliHLTLogging {
     AliHLTUInt32_t          fIndex; //!transient
   };
 
+  class AliHLTOUTHandlerListEntry {
+  public:
+    AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, 
+                             AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
+                             AliHLTModuleAgent* pAgent,
+                             AliHLTUInt32_t index);
+
+    /** copy constructor for vector handling */
+    AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
+
+    /** assignment operator for vector handling */
+    AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
+
+    ~AliHLTOUTHandlerListEntry();
+
+    static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
+
+    operator AliHLTOUTHandler*() const {return fpHandler;}
+
+    // please note that fpHandlerDesc is really a pointer and is created
+    // in the constructor. Thats why it is dereferenced here. The pointer
+    // type is on purpose, even though it is a bit confusing with the 
+    // argument by reference in the AliHLTOUTHandlerListEntry constructor.
+    operator const AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const 
+    {return fpHandlerDesc?*fpHandlerDesc:AliHLTModuleAgent::fgkVoidHandlerDesc;}
+    operator AliHLTModuleAgent*() const {return fpAgent;}
+
+    /**
+     * Two list entries are considered to be equal if the handlers
+     * are equal.
+     */
+    bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
+
+    bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const;
+
+    AliHLTUInt32_t operator[](int i) const;
+
+    /**
+     * Add a block index to this descriptor.
+     * One descriptor can serve multiple blocks if the agent returns the
+     * same handler for all of the blocks. Instead of creating a new entry
+     * the block index ist just added
+     */
+    void AddIndex(AliHLTUInt32_t index);
+
+    /**
+     * Add all indexes of the descriptor.
+     */
+    void AddIndex(AliHLTOUTHandlerListEntry &desc);
+
+    /**
+     * Check if an index is served by this descriptor.
+     * @return true if the index is in the table
+     */
+    bool HasIndex(AliHLTUInt32_t index);
+
+  private:
+    /** standard constructor prohibited */
+    AliHLTOUTHandlerListEntry();
+
+    /** pointer to the handler */
+    AliHLTOUTHandler* fpHandler; //! transient
+
+    /** pointer to handler description */
+    AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
+
+    /** pointer to module agent */
+    AliHLTModuleAgent* fpAgent; //! transient
+
+    /** list of block indexes */
+    AliHLTOUTIndexList fBlocks; //!transient
+  };
+
+  typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
+  typedef vector<AliHLTOUTBlockDescriptor>  AliHLTOUTBlockDescriptorVector;
+
+  /**
+   * Init for processing.
+   * The HLTOUT is scanned for all available data blocks and the
+   * AliHLTOUTHandler objects for the data blocks are created according
+   * to the module agents (see AliHLTModuleAgent).
+   */
+  int Init();
+
+  /**
+   * Get number of data blocks in the HLTOUT data
+   */
+  int GetNofDataBlocks();
+
+  /**
+   * Select the first data block of a certain data type and specification.
+   * The selection criteria can be of kAliHLTAnyDataType and/or
+   * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
+   *
+   * The search criteria can be combined with a handler type (e.g. kRawReader)
+   * @param dt    [in]  data type to match                                <br>
+   * @param spec  [in]  data specification to match                       <br>
+   * @param handlerType [in]  type of the handler
+   * @return identifier >0 if success, 0 if no block found                <br>
+   *         neg. error code if failed                                    <br>
+   *                        -EPERM if access denied (object locked)
+   */
+  int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
+                          AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
+                          AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
+
+  /**
+   * Select the next data block of data type and specification of the previous
+   * call to @ref SelectFirstDataBlock.
+   * @return identifier >0 if success, 0 if no block found                <br>
+   *         neg. error code if failed                                    <br>
+   *                        -EPERM if access denied (object locked)
+   */
+  int SelectNextDataBlock();
+
+  /**
+   * Get properties of the selected data block.
+   * @param dt    [out] data type of the selected block
+   * @param spec  [out] data specification of the selected block
+   */
+  int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
+
+  /**
+   * Get handler description of the current data block.
+   */
+  const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc();
+
+  /**
+   * Get handler type of the selected data block.
+   * @return handler type for the selected data block
+   */
+  AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType();
+
+  /**
+   * Get the index of the current data block.
+   * @return index, AliHLTOUTInvalidIndex if no block selected
+   */
+  AliHLTUInt32_t GetDataBlockIndex();
+
+  /**
+   * Get buffer of the selected data block.
+   * @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);
+
+  /**
+   * Release buffer after use.
+   * @param pBuffer [in]  buffer of the selected data block
+   */
+  int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
+
+  /**
+   * Get module agent for the selected data block.
+   */
+  AliHLTModuleAgent* GetAgent();
+
+  /**
+   * Get handler for the selected data block.
+   */
+  AliHLTOUTHandler* GetHandler();
+
+  /**
+   * Convert data buffer to ESD.
+   * The buffer is supposed to describe a streamed AliESDEvent object.
+   * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
+   * where 'det' is derived from the data type origin. Each time the function is invoked
+   * a new event is created. Dummy events are added if the previous events did not contain
+   *
+   * The function needs AliRoot and might not be implemented by all AliHLTOUT
+   * implementations.
+   * a data block of this specification.
+   * @param pBuffer  [in] the data buffer
+   * @param size     [in] data buffer size
+   * @param dt       [in] data type of the block
+   * @param tgtesd   [out] optional target
+   */
+  virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
+
   enum AliHLTOUTByteOrder {
     /** no data block selected */
     kInvalidByteOrder=-1,
@@ -236,6 +347,17 @@ class AliHLTOUT : public AliHLTLogging {
    */
   static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src);
 
+  /**
+   * Insert a handler item.
+   * The current list entries are checked if the handler is already in
+   * the list. It is added if not in the list, otherwise the block index
+   * is added to the existing entry.
+   * @param entry    handler list entry
+   * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
+   *         neg. error code if failed
+   */
+  static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry);
+  
  protected:
   /**
    * Add a block descriptor.
@@ -280,78 +402,6 @@ class AliHLTOUT : public AliHLTLogging {
     kAlignmentWarning = 0x20
   };
 
-  class AliHLTOUTHandlerListEntry {
-  public:
-    AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, 
-                             AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
-                             AliHLTModuleAgent* pAgent,
-                             AliHLTUInt32_t index);
-
-    /** copy constructor for vector handling */
-    AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
-
-    /** assignment operator for vector handling */
-    AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
-
-    ~AliHLTOUTHandlerListEntry();
-
-    static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
-
-    operator AliHLTOUTHandler*() const {return fpHandler;}
-
-    // please note that fpHandlerDesc is really a pointer and is created
-    // in the constructor. Thats why it is dereferenced here. The pointer
-    // type is on purpose, even though it is a bit confusing with the 
-    // argument by reference in the AliHLTOUTHandlerListEntry constructor.
-    operator AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const {return *fpHandlerDesc;}
-    operator AliHLTModuleAgent*() const {return fpAgent;}
-
-    /**
-     * Two list entries are considered to be equal if the handlers
-     * are equal.
-     */
-    bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
-
-    bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const;
-
-    AliHLTUInt32_t operator[](int i) const;
-
-    /**
-     * Add a block index to this descriptor.
-     * One descriptor can serve multiple blocks if the agent returns the
-     * same handler for all of the blocks. Instead of creating a new entry
-     * the block index ist just added
-     */
-    void AddIndex(AliHLTUInt32_t index);
-
-    /**
-     * Add all indexes of the descriptor.
-     */
-    void AddIndex(AliHLTOUTHandlerListEntry &desc);
-
-    /**
-     * Check if an index is served by this descriptor.
-     * @return true if the index is in the table
-     */
-    bool HasIndex(AliHLTUInt32_t index);
-
-  private:
-    /** standard constructor prohibited */
-    AliHLTOUTHandlerListEntry();
-
-    /** pointer to the handler */
-    AliHLTOUTHandler* fpHandler; //! transient
-
-    /** pointer to handler description */
-    AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
-
-    /** pointer to module agent */
-    AliHLTModuleAgent* fpAgent; //! transient
-
-    /** list of block indexes */
-    AliHLTOUTIndexList fBlocks; //!transient
-  };
-  
   /**
    * Generate the index of the HLTOUT data.
    * Must be implemented by the child classes.
@@ -416,17 +466,6 @@ class AliHLTOUT : public AliHLTLogging {
    */
   int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
 
-  /**
-   * Insert a handler item.
-   * The current list entries are checked if the handler is already in
-   * the list. It is added if not in the list, otherwise the block index
-   * is added to the existing entry.
-   * @param entry    handler list entry
-   * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
-   *         neg. error code if failed
-   */
-  int InsertHandler(const AliHLTOUTHandlerListEntry &entry);
-
   /**
    * Find handler description for a certain block index.
    */
@@ -444,9 +483,6 @@ class AliHLTOUT : public AliHLTLogging {
   /** instance flags: locked, collecting, ... */
   unsigned int fFlags; //!transient
 
-  typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
-  typedef vector<AliHLTOUTBlockDescriptor>  AliHLTOUTBlockDescriptorVector;
-
   /** list of block descriptors */
   AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
 
index 8bc6b0a23d768cc9010e5856bcb76f462bda969e..789d5006ec06c02c840d6680fd5878cd0c4d7d1f 100644 (file)
@@ -126,7 +126,7 @@ int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt
 
     // first check if the offset allows to add all data blocks without exceeding the
     // range
-    while (nofBlocks<tmp1 && tmp2>0) {
+    while (nofBlocks>tmp1 && tmp2>0) {
       if (tmp2&0x1) {
        HLTError("index range %#x exceeded for %d data blocks", nofBlocks, offset);
        iResult=-ERANGE;
index f52067887f8feb3f40358f18d7e41f6745a63012..ee3b15d65463aed006ea4c2fc0661625d85d6103 100644 (file)
  *
  * @note This class is only used for the @ref alihlt_system.
  *
+ * @note This class is very likely to be deprecated. According to the new
+ * reconstruction scheme, the esd is no longer filled by components in the
+ * reconstruction chain, but added to the HLTOUT data. The HLTOUT is
+ * processed during AliReconstruction at the end of the HLT event processing,
+ * literally during the FillESD method of the AliRoot reconstruction
+ * interface. The HLT module must implement HLTOUT handlers and provide
+ * those through the module agent.
+ *
  * @ingroup alihlt_system
  */
 class AliHLTOfflineDataSink 
index 84f7fcca9c9befb8793a92bf63049995ac7511c2..5d89811e783221523fa468593d3eb71b1522bfaf 100644 (file)
@@ -160,7 +160,7 @@ int AliHLTOfflineInterface::FillComponentESDs(int eventNo, AliRunLoader* runLoad
     if (pCurrent) {
       pCurrent->SetESD(eventNo, esd);
       if (pCurrent->GetRunLoader()!=runLoader) {
-       //HLTWarning("runLoader missmatch: component %p was reconstructed with runLoader %p, but got %p now", pCurrent, pCurrent->GetRunLoader(), runLoader);
+       //HLTWarning("runLoader mismatch: component %p was reconstructed with runLoader %p, but got %p now", pCurrent, pCurrent->GetRunLoader(), runLoader);
       }
       iLocal=pCurrent->FillESD(eventNo, runLoader, esd);
     }
index f4286bd846f0c980e3c06abf89b7682e265dd08b..f53c463f7a751aa3cba8cf2cd53742c78b3c0dbd 100644 (file)
@@ -1,20 +1,20 @@
 // $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   AliHLTSystem.cxx
     @author Matthias Richter
     @brief  Implementation of HLT module management.
 */
 
-// 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 __GNUC__>= 3
 using namespace std;
 #endif
@@ -43,6 +37,8 @@ using namespace std;
 #include "AliHLTModuleAgent.h"
 #include "AliHLTOfflineInterface.h"
 #include "AliHLTDataSource.h"
+#include "AliHLTOUT.h"
+#include "AliHLTOUTHandler.h"
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
@@ -59,6 +55,7 @@ const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
   //"libAliHLTPHOS.so",
   //"libAliHLTMUON.so",
   "libAliHLTTRD.so",
+  "libAliHLTTrigger.so",
   NULL
 };
 
@@ -199,7 +196,7 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
     AliHLTTask* pTask=NULL;
     if ((pTask=FindTask(pConf->GetName()))!=NULL) {
       if (pTask->GetConf()!=pConf) {
-       HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
+       HLTError("configuration mismatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
        iResult=-EEXIST;
       }
       // task for this configuration exists, terminate
@@ -702,6 +699,109 @@ int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd
   return iResult;
 }
 
+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());
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
+  for (iResult=pHLTOUT->SelectFirstDataBlock();
+       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 (!pHandler && (dt!=kAliHLTDataTypeESDObject || dt!=kAliHLTDataTypeESDTree)) {
+      handlerType=AliHLTModuleAgent::kEsd;
+    }
+    const char* pMsg="invalid";
+    switch (handlerType) {
+    case AliHLTModuleAgent::kEsd:
+      {
+       if (pHandler) {
+         // preprocess and write later
+         AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
+         pHandler->ProcessData(pHLTOUT);
+         pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
+       } else {
+         // write directly
+         const AliHLTUInt8_t* pBuffer=NULL;
+         AliHLTUInt32_t size=0;
+         if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
+           pHLTOUT->WriteESD(pBuffer, size, dt);
+           pHLTOUT->ReleaseDataBuffer(pBuffer);
+         }
+       }
+      }
+      break;
+    case AliHLTModuleAgent::kRawReader:
+      // handled in the AliRawReaderHLT
+      break;
+    case AliHLTModuleAgent::kRawStream:
+      HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                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",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      break;
+    case AliHLTModuleAgent::kProprietary:
+      HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      if (pHandler) {
+       AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
+       int res=pHandler->ProcessData(pHLTOUT);
+       if (res<0) {
+         HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
+                    res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                    AliHLTComponent::DataType2Text(dt).c_str(), spec);
+       }
+      }
+      break;
+    case AliHLTModuleAgent::kUnknownOutput:
+      pMsg="unknown";
+      // fall trough intended
+    default:
+      HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+    }
+  }
+  // TODO: the return value of SelectFirst/NextDataBlock must be
+  // changed in order to avoid this check
+  if (iResult==-ENOENT) iResult=0;
+
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
+  // write all postponed esd data blocks
+  // first come first serve: the ESD of the first handler is also filled into
+  // the main ESD. Has to be changed later.
+  AliESDEvent* pMasterESD=esd;
+  for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
+    AliHLTOUTHandler* pHandler=*esdHandler;
+    const AliHLTUInt8_t* pBuffer=NULL;
+    AliHLTUInt32_t size=0;
+    if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+      AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
+      AliHLTComponentDataType dt=desc;
+      pHLTOUT->WriteESD(pBuffer, size, dt);
+      if (pMasterESD) {
+       pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
+       pMasterESD=NULL;
+      }
+      pHandler->ReleaseProcessedData(pBuffer, size);
+    }
+  }
+
+  return iResult;
+}
+
 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
 {
   // see header file for class documentation
index 530da6074e6e6263a6681ba362c71119de40d987..dc92866e88505ba1e50d41ee592f613a66ba8b7f 100644 (file)
@@ -3,8 +3,9 @@
 
 #ifndef ALIHLTSYSTEM_H
 #define ALIHLTSYSTEM_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice                               */
+//* 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   AliHLTSystem.h
     @author Matthias Richter
     @note   The class is used in Offline (AliRoot) context
 */
 
-// see below for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
-
 /**
  * @defgroup alihlt_system HLT integration into AliRoot
  * This section describes the HLT integration into AliRoot.
@@ -32,6 +27,7 @@ class AliHLTComponentHandler;
 class AliHLTConfiguration;
 class AliHLTConfigurationHandler;
 class AliHLTTask;
+class AliHLTOUT;
 class AliRunLoader;
 class AliRawReader;
 class AliESDEvent;
@@ -251,6 +247,18 @@ class AliHLTSystem : public AliHLTLogging {
    * Fill ESD for one event.
    * To be called by the AliHLTReconstructor plugin during the event loop
    * and FillESD method of the AliRoot reconstruction.
+   *
+   * The method is most likely deprecated as the scheme has been slightly
+   * changed. The ESD is filled by the HLTOUT handlers u=implemented by the
+   * HLT modules rather than by components within the reconstruction chain.
+   * Still, HLT reconstruction chains can be run during the AliRoot
+   * reconstruction, data produced by such chains is automatically added
+   * to the HLTOUT stream in order to be equivalent to the online HLT.
+   * The HLTOUT is processed during AliReconstruction at the end of the
+   * HLT event processing, literally during the FillESD method of the AliRoot
+   * reconstruction interface. The HLT module must implement HLTOUT handlers
+   * and provide those through the module agent.
+   *
    * This method is called on event basis, and thus must copy the previously
    * reconstructed data of the event from the 'ESD' recorder. The FillESD
    * method of all active AliHLTOfflineDataSink's is called.
@@ -263,6 +271,11 @@ class AliHLTSystem : public AliHLTLogging {
    */
   int FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd);
 
+  /**
+   * Process the HLTOUT data.
+   */
+  int ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd);
+
   /**
    * Load component libraries.
    * @param libs          string of blank separated library names
index 7bd78ebb4333c8f8aa3f0a009f747562f79419d9..dd88de9e983baf34d4a66f42c579cb2dc7915b73 100644 (file)
@@ -22,7 +22,7 @@ bin_SCRIPTS                   = setenv.sh setenv.csh
 lib_LTLIBRARIES                        =  libHLTbase.la
 
 # version info for the library
-LIBRARY_VERSION                        = '4:0:1'
+LIBRARY_VERSION                        = '5:0:2'
 
 # MODDIR is set by the AliRoot build system and denotes the topdir
 # of the module, we must set it since the package definition libHLTbase.pkg
index 747ff688aba1cdd28da3c187608022804b95ae17..ff3f91596d03b63a9ca30f2528fa410de38c7232 100644 (file)
@@ -140,3 +140,19 @@ int AliHLTSystemSetOptions(AliHLTSystem* pInstance, const char* options)
   }
   return iResult;
 }
+
+int AliHLTSystemProcessHLTOUT(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd)
+{
+  int iResult=0;
+  if (pInstance) {
+    AliHLTSystem* pSystem=reinterpret_cast<AliHLTSystem*>(pInstance);
+    if (pSystem) {
+      iResult=pSystem->ProcessHLTOUT(pHLTOUT, esd);
+    } else {
+      iResult=-EFAULT;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
index 44789fa768aba4d79cd67b68aa464ea41b7c9a17..4d499ffc5c0d082fc76dc345d898d6faba42920c 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <AliHLTDataTypes.h>
 class AliHLTSystem;
+class AliHLTOUT;
+class AliESDEvent;
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -158,6 +160,17 @@ int AliHLT_C_GetOutputSize( AliHLTComponentHandle, unsigned long* constBase, dou
  */
 int AliHLTSystemSetOptions(AliHLTSystem*, const char*);
 
+/**
+ * Process the HLTOUT data with the specified system instance.
+ * The function is introduced for the sake of backward compatibility.
+ * Called from AliHLTReconstructor, which loads the function dynamically.
+ * @return neg. error code if failed                                     <br>
+ *         -EFAULT    type cast failed                                   <br>
+ *         -EINVAL    invalid parameter
+ * @ingroup alihlt_system_interface
+ */
+int AliHLTSystemProcessHLTOUT(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd);
+
 #ifdef __cplusplus
 }
 #endif
index ea7c56261399a2ce512291fcbf92d5fd07aa7da8..1f146c8b17c967bb0a8669ba46b2b9c0a8571a6c 100644 (file)
@@ -344,8 +344,8 @@ int AliHLTAltroGenerator::EncodeData(AliHLTUInt8_t* pBuffer, int size)
       int startTime=fpSimData->At(dataPos++);
       int time=startTime;
       for (; time<startTime+bunchLength; time++) {
-       //iResult=encoder.AddSignal(fpSimData->At(dataPos++), time);
-       iResult=encoder.AddChannelSignal(fpSimData->At(dataPos++), time, channelAddress);
+       iResult=encoder.AddSignal(fpSimData->At(dataPos++), time);
+       //iResult=encoder.AddChannelSignal(fpSimData->At(dataPos++), time, channelAddress);
       }
       assert(time-1==fpSimData->At(dataPos));
       dataPos++; // DO NOT PUT INTO ASSERT
@@ -359,10 +359,10 @@ int AliHLTAltroGenerator::EncodeData(AliHLTUInt8_t* pBuffer, int size)
       assert(channelAddress==fpSimData->At(dataPos));
       dataPos++; // DO NOT PUT INTO ASSERT
     }
-    //encoder.SetChannel(channelAddress);
+    encoder.SetChannel(channelAddress);
   }
   if (iResult>=0 && channelAddress>=0) {
-    encoder.SetChannel(channelAddress);
+    //encoder.SetChannel(channelAddress);
   }
 
   if (iResult>=0) {
index acf56c8632d51beac38d815e07d28a47f809fbe2..f51102d43071769046d8b637afd53b52ddbaefae 100644 (file)
@@ -11,7 +11,7 @@
  * @file   AliHLTSamplePreprocessor.h
  * @author Kenneth Aamodt, Sebastian Bablok
  * @date   2007-12-06
- * @brief  HLT Preprocessor plugin for the AliHLTComp library
+ * @brief  HLT Preprocessor plugin for the AliHLTSample library
  */
 
 // see below for class documentation
@@ -24,9 +24,7 @@
 
 /**
  * @class AliHLTSamplePreprocessor
- * HLT preprocessor for the libAliHLTComp module.
- *
- * @author Jenny Wagner, Matthias Richter
+ * A sample HLT preprocessor.
  *
  * @date 2008-01-22
  */
index 79722bb4a9df2d71e6313ceda7e2c025f8e5f420..4e0b5183202d1b0609a2c180614128243cc92423 100644 (file)
@@ -1,28 +1,28 @@
 // @(#) $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   AliHLTTPCEsdWriterComponent.cxx
     @author Matthias Richter
     @date   
     @brief  Writer component to store tracks of the HLT TPC conformal
             mapping tracker in the AliESD format
+*/
 
-                                                                          */
 // see header file for class documentation
 // or
 // refer to README to build package
@@ -179,7 +179,7 @@ int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
          if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
            if (minslice!=maxslice) {
              HLTWarning("data from multiple sectors in one block: "
-                        "possible missmatch in treatment of local coordinate system");
+                        "possible mismatch in treatment of local coordinate system");
            }
            AliHLTTPCTrackArray tracks;
            inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
@@ -226,7 +226,7 @@ int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESD
          HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
        }
       } else {
-       HLTError("internal missmatch in array");
+       HLTError("internal mismatch in array");
        iResult=-EFAULT;
       }
     }
@@ -273,7 +273,7 @@ void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long&
 {
   // see header file for class documentation
   constBase=1000000;
-  inputMultiplier=1.0;
+  inputMultiplier=5.0;
 }
 
 int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
index 96f39a9b044f5879abf5b33e919f9ea35d04354d..e91d8b704b636951940ac67ae3fd616587bf5757 100644 (file)
@@ -54,6 +54,8 @@
 #include "AliHLTTPCSpacePointData.h"
 //#include "AliHLTTPCTrackArray.h"
 #include "AliHLTTPCFileHandler.h"
+#include "AliHLTTPCMapping.h"
+#include "AliHLTAltroEncoder.h"
 
 #if __GNUC__ >= 3
 using namespace std;
@@ -621,6 +623,88 @@ AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliDigits2Memory(UInt_t & nrow,Int
   return data;
 }
 
+int AliHLTTPCFileHandler::AliDigits2Altro(Int_t event, Byte_t* tgtBuffer, UInt_t tgtSize)
+{
+  //Read data from AliROOT file into memory, and store it in the ALTRO data format
+  //in the provided buffer 
+  //Returns: size of the encoded data in bytes
+  int iResult=0;
+
+  if(!fInAli){
+    LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Altro","File")
+    <<"No Input avalible: Pointer to fInAli == NULL"<<ENDLOG;
+    return 0; 
+  }
+
+  if (!tgtBuffer) {
+    return -EINVAL;
+  }
+
+  if(!fDigitsTree)
+    if(!GetDigitsTree(event)) return 0;
+
+  UShort_t dig;
+  Int_t time=0;
+  Int_t pad=0;
+  Int_t sector=0;
+
+  AliHLTTPCMapping mapper(fPatch);
+  AliHLTAltroEncoder encoder;
+  encoder.SetBuffer(tgtBuffer, tgtSize);
+
+  // The digits of the current event have been indexed: all digits are organized in
+  // rows, all digits of one row are stored in a AliSimDigits object (fDigit) which
+  // are stored in the digit tree.
+  // The index map relates the AliSimDigits objects in the tree to dedicated pad rows
+  // in the TPC
+  // This loop filters the pad rows according to the slice no set via Init
+
+  assert(fRowMax<fgkNRow);
+  for(Int_t r=fRowMin;r<=fRowMax && r<fgkNRow && iResult>=0;r++){
+    Int_t n=fIndex[fSlice][r];
+
+    Int_t row=0;
+    Int_t rowOffset=0;
+    AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row);
+    AliHLTTPCTransform::Slice2Sector(fSlice,AliHLTTPCTransform::GetFirstRow(fPatch),sector,rowOffset);
+
+    if(n!=-1){//data on that row
+      Int_t lslice,lrow;
+      fDigitsTree->GetEvent(n);
+      fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
+      AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
+      if(lrow!=r){
+       LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2Altro","Row")
+         <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
+       continue;
+      }
+
+      Int_t channelAddress=-1;
+      fDigits->First();
+      do {
+       time=fDigits->CurrentRow();
+       pad=fDigits->CurrentColumn();
+       dig = fDigits->GetDigit(time,pad);
+       if (dig <= fParam->GetZeroSup()) continue;
+       if(dig >= AliHLTTPCTransform::GetADCSat())
+         dig = AliHLTTPCTransform::GetADCSat();
+       
+       channelAddress=mapper.GetHwAddress(row-rowOffset, pad);
+       iResult=encoder.AddChannelSignal(dig, time, channelAddress);
+      } while (fDigits->Next() && iResult>=0);
+      if (iResult>=0 && channelAddress>=0) {
+       iResult=encoder.SetChannel(channelAddress);
+      }
+    }
+  }
+
+  if (iResult>=0) {
+    iResult=(encoder.GetTotal40bitWords()*5)/4;
+  }
+
+  return iResult;
+}
+
 AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge)
 {
   //Read data from AliROOT file into memory, and store it in the HLT data format.
index b95e190666c9ac68653a6269feb09a0fc4fb1483..9ec32d3a38feecf43de664ad9c47ee901946659f 100644 (file)
@@ -101,18 +101,23 @@ class AliHLTTPCFileHandler:public AliHLTTPCMemHandler {
   }
 
   /**
-   * Convert and filetr AliDigits from AliRoot file to HLT Digit data in memory.
+   * Convert and filter AliDigits from AliRoot file to HLT Digit data in memory.
    * This functions is the same as @ref AliDigits2Memory but in addition it
    * filters out single timebins, which is noise. The timebins which
    * are removed are timebins which have the 4 zero neighbours; 
    * (pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1).
    *
-   * This is legacy code, the two function contain big portions of identical code
+   * This is legacy code, the two functions contain big portions of identical code
    * will be merged.
    * See @ref AliDigits2Memory for detailed description.
    */
   AliHLTTPCDigitRowData *AliAltroDigits2Memory(UInt_t & nrow,Int_t event=0,Bool_t eventmerge=kFALSE); 
 
+  /**
+   * Convert AliDigits from AliRoot file to Altro data format in memory.
+   */
+  int AliDigits2Altro(Int_t event, Byte_t* tgtBuffer, UInt_t size);
+
   /**
    * Write AliDigits from AliRoot file to binary file.
    * @param event      event no
diff --git a/HLT/TPCLib/macros/dumpTPCDigits.C b/HLT/TPCLib/macros/dumpTPCDigits.C
new file mode 100644 (file)
index 0000000..4279d7e
--- /dev/null
@@ -0,0 +1,141 @@
+// $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   dumpTPCDigits.C
+ * @author Matthias.Richter@ift.uib.no
+ * @date   
+ * @brief  Convert TPC digit info to ascii and print to stdout.
+ *
+ * The macro reads the simulated TPC digits from the RunLoader and
+ * prints the digit info to stout.
+ *
+ * aliroot -b -q dumpTPCDigits.C | tee digits.log
+ *
+ * The macro asumes the data to be already simulated.
+ */
+
+#ifndef __CINT__
+#include "TSystem.h"
+#include "TTree.h"
+#include "AliRunLoader.h"
+#include "AliSimDigits.h"
+#endif //__CINT__
+
+int dumpDigits(AliRunLoader* runloader, int event);
+
+int dumpTPCDigits()
+{
+  const char* galice_file="galice.root";
+  TString param=galice_file;
+  param+="?filetype=raw";
+  TFile file(param);
+  if (file.IsZombie()) {
+    cerr << "can not open file " << galice_name << ", skipping test" << endl;
+    return 0;
+  }
+
+  AliRunLoader* rl=AliRunLoader::Open(galice_file);
+  if (!rl) {
+    cerr << "can not open RunLoader" << endl;
+    return -1;
+  }
+
+  gSystem->Load("libAliHLTTPC.so");
+
+  dumpDigits(rl, 0);
+
+  return 0;
+}
+
+int dumpDigits(AliRunLoader* runloader, int event)
+{
+  int iResult=0;
+  AliLoader* tpcLoader = runloader->GetLoader("TPCLoader");
+  if(!tpcLoader){
+    cerr << "error: can not get TPC loader" << endl;
+    return -1;
+  }
+
+  runloader->GetEvent(event);
+  tpcLoader->LoadDigits();
+
+  TTree *digitsTree = tpcLoader->TreeD();
+  if(!digitsTree) {
+    cerr << "error: can not get digits tree for event no " << event << endl;
+    return -1;
+  }
+
+  AliSimDigits *digits;
+  digitsTree->GetBranch("Segment")->SetAddress(&digits);
+
+  AliTPCParam *tpcParam;
+  runloader->CdGAFile();
+  tpcParam = (AliTPCParam*)gFile->Get("75x40_100x60_150x60");
+  if(!tpcParam){
+    cerr << "error: can not retrieve parameters" << endl;
+  }
+
+  Int_t iPrintedSlice=-1;
+  Int_t iPrintedPart=-1;
+
+  for(Int_t n=0; n<digitsTree->GetEntries(); n++) {
+    Int_t sector, row; // coordinates of the simualted data
+    Int_t lslice,lrow; // local coordinates
+    digitsTree->GetEvent(n);
+    tpcParam->AdjustSectorRow(digits->GetID(),sector,row);
+    if(!AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row)){
+      cerr << "error: conversion of coordinates sector/row " << sector << "/" << row << "failed" << endl;
+      return -1;
+    }
+
+    Int_t part=AliHLTTPCTransform::GetPatch(lrow);
+
+    if (iPrintedSlice!=lslice || iPrintedPart!=part) {
+      iPrintedSlice=lslice;
+      iPrintedPart=part;
+      cout << "====================================================================" << endl;
+      cout << "    Slice: " << iPrintedSlice << "   Partition: " << iPrintedPart << "   digit tree entry " << n << endl;
+    }
+
+    cout << "--------------------------------------------------------------------" << endl;
+    cout << "Row: " << lrow << endl;
+
+    digits->First();
+    Int_t lasttime=-1;
+    Int_t lastpad=-1;
+    do {
+      Int_t time=digits->CurrentRow();
+      Int_t pad=digits->CurrentColumn();
+      Int_t dig = digits->GetDigit(time,pad);
+      if (lastpad!=pad) {
+       if (lastpad!=-1) cout << "        -> " << lasttime << endl;
+       lastpad=pad;
+       cout << "Row: " << lrow << "  Pad: " << lastpad << endl;
+       lasttime=-1;
+      }
+      if (lasttime!=time+1 && lasttime!=time-1 ) {
+       if (lasttime!=-1) cout << "        -> " << lasttime << endl;
+       cout << "                     Time " << time << ":  ";
+      }
+      lasttime=time;
+      cout << "  " << dig;
+    } while (digits->Next());
+    if (lasttime) cout << "        -> " << lasttime << endl;
+  }
+}
index c82c6a1f1758fdaf9e5df6f47aef3029b9b92310..814926270c7de88835b8da5ec4ca8ac52eec34ca 100644 (file)
@@ -8,7 +8,7 @@
  * The chain to be run is defined by the macro given to the parameter
  * 'config='
  *
- * The makro asumes the data to be already simulated. If it should run
+ * The macro asumes the data to be already simulated. If it should run
  * within the initial simulation, comment the corresponding functions
  * below (SetRunGeneration etc.)
  *
index 7bef44a5ee5ac4616ea7d5a86607f4f137ff0cd7..9cb2887c358977349968e393c97ed0d08092ec34 100644 (file)
@@ -3,10 +3,13 @@
 
 include $(MODDIR)/hlt.conf
 
-LIBHLTREC_VERSION := 0
+LIBHLTREC_VERSION := 1
 
 CLASS_HDRS:=   AliHLTReconstructor.h \
                AliRawReaderHLT.h \
+               AliHLTOUTHomerCollection.h \
+               AliHLTEsdManager.h \
+               AliHLTOUTDigitReader.h \
                AliHLTOUTRawReader.h
 
 MODULE_SRCS:=  AliHLTDynamicAliLog.cxx \
diff --git a/HLT/rec/AliHLTEsdManager.cxx b/HLT/rec/AliHLTEsdManager.cxx
new file mode 100644 (file)
index 0000000..66049b8
--- /dev/null
@@ -0,0 +1,269 @@
+// $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   AliHLTEsdManager.cxx
+    @author Matthias Richter
+    @date   
+    @brief  Manager for merging and writing of HLT ESDs
+*/
+
+#include "AliHLTEsdManager.h"
+#include "AliHLTComponent.h"
+#include "AliESDEvent.h"
+#include "AliHLTMessage.h"
+#include "AliESDEvent.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TClass.h"
+#include "TObject.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTEsdManager)
+
+AliHLTEsdManager::AliHLTEsdManager()
+  :
+  fESDs()
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTEsdManager::~AliHLTEsdManager()
+{
+  // see header file for class documentation
+}
+
+AliHLTEsdManager::AliHLTEsdListEntry* AliHLTEsdManager::Find(AliHLTComponentDataType dt) const
+{
+  // see header file for class documentation
+  AliHLTEsdListEntry* pEntry=NULL;
+  for (unsigned int i=0; i<fESDs.size(); i++) {
+    if (fESDs[i]==dt) {
+      pEntry=const_cast<AliHLTEsdListEntry*>(&fESDs[i]);
+    }
+  }
+  return pEntry;
+}
+
+int AliHLTEsdManager::WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
+                              AliHLTComponentDataType dt, AliESDEvent* tgtesd, int eventno)
+{
+  // see header file for class documentation
+  if (!pBuffer && size<=0) return -EINVAL;
+  int iResult=0;
+  AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
+  if (firstWord==size-sizeof(AliHLTUInt32_t)) {
+    HLTDebug("create object from block %s size %d", AliHLTComponent::DataType2Text(dt).c_str(), size);
+    AliHLTMessage msg(const_cast<AliHLTUInt8_t*>(pBuffer), size);
+    TClass* objclass=msg.GetClass();
+    TObject* pObj=msg.ReadObject(objclass);
+    if (pObj && objclass) {
+      HLTDebug("object %p type %s created", pObj, objclass->GetName());
+      AliESDEvent* pESD=dynamic_cast<AliESDEvent*>(pObj);
+      TTree* pTree=NULL;
+      if (!pESD) {
+       pTree=dynamic_cast<TTree*>(pObj);
+       if (pTree) {
+         pESD=new AliESDEvent;
+         pESD->CreateStdContent();
+         if (pTree->GetEntries()>0) {
+           if (pTree->GetEntries()>1) {
+             HLTWarning("only one entry allowed for ESD embedded into tree, data block %s contains tree with %d entires, taking first entry",
+                        AliHLTComponent::DataType2Text(dt).c_str(), pTree->GetEntries());
+           }
+           pESD->ReadFromTree(pTree);
+           pTree->GetEvent(0);
+         }
+       } else {
+         HLTWarning("tree of data block %s has no events, skipping data block", AliHLTComponent::DataType2Text(dt).c_str());
+       }
+      }
+      if (pESD) {
+       AliHLTEsdListEntry* entry=Find(dt);
+       if (!entry) {
+         AliHLTEsdListEntry newEntry(dt);
+         fESDs.push_back(newEntry);
+       }
+       if (tgtesd) {
+       }
+       entry=Find(dt);
+       if (entry) {
+         entry->WriteESD(pESD, eventno);
+       } else {
+         HLTError("internal mismatch, can not create list entry");
+         iResult=-ENOMEM;
+       }
+      } else {
+       HLTWarning("data block %s is not of class type AliESDEvent, ignoring ...", AliHLTComponent::DataType2Text(dt).c_str());
+      }
+      if (pTree) {
+       // ESD has been created and must be cleaned up
+       delete pESD;
+       pESD=NULL;
+      }
+      delete pObj;
+      pObj=NULL;
+    } else {
+    }
+  }
+  return iResult;
+}
+
+AliHLTEsdManager::AliHLTEsdListEntry::AliHLTEsdListEntry(AliHLTComponentDataType dt)
+  :
+  fName(),
+  fpFile(NULL),
+  fpTree(NULL),
+  fpEsd(NULL),
+  fDt(dt)
+{
+  // see header file for class documentation
+}
+
+AliHLTEsdManager::AliHLTEsdListEntry::AliHLTEsdListEntry(const AliHLTEsdListEntry& src)
+  :
+  AliHLTLogging(),
+  fName(src.fName),
+  fpFile(src.fpFile),
+  fpTree(src.fpTree),
+  fpEsd(src.fpEsd),
+  fDt(src.fDt)
+{
+  // copy constructor copies everything including pointers
+}
+
+AliHLTEsdManager::AliHLTEsdListEntry& AliHLTEsdManager::AliHLTEsdListEntry::operator=(const AliHLTEsdListEntry& src)
+{
+  // assignment operator copies everything including pointers
+  fName=src.fName;
+  fpFile=src.fpFile;
+  fpTree=src.fpTree;
+  fpEsd=src.fpEsd;
+  fDt=src.fDt;
+  return *this;
+}
+
+AliHLTEsdManager::AliHLTEsdListEntry::~AliHLTEsdListEntry()
+{
+  // see header file for class documentation
+  if (fpTree) {
+    delete fpTree;
+    fpTree=NULL;
+  }
+
+  if (fpEsd) {
+    delete fpEsd;
+    fpEsd=NULL;
+  }
+
+  if (fpFile) {
+    fpFile->Close();
+    delete fpFile;
+    fpFile=NULL;
+  }
+}
+
+bool AliHLTEsdManager::AliHLTEsdListEntry::operator==(AliHLTComponentDataType dt) const
+{
+  // see header file for class documentation
+  return fDt==dt;
+}
+
+int AliHLTEsdManager::AliHLTEsdListEntry::WriteESD(AliESDEvent* pESD, int eventno)
+{
+  // see header file for class documentation
+  if (!pESD) return -EINVAL;
+  int iResult=0;
+  if (!fpFile) {
+    TString origin;
+    origin.Insert(0, fDt.fOrigin, kAliHLTComponentDataTypefOriginSize);
+    origin.Remove(TString::kTrailing, ' ');
+    origin.ToUpper();
+    fName="AliHLT"; fName+=origin;
+    if (fDt!=kAliHLTDataTypeESDObject &&
+       fDt!=kAliHLTDataTypeESDTree) {
+
+      HLTWarning("non-standard ESD type %s", AliHLTComponent::DataType2Text(fDt).c_str());
+      TString id;
+      id.Insert(0, fDt.fID, kAliHLTComponentDataTypefIDsize);
+      id.Remove(TString::kTrailing, ' ');
+      id.ToUpper();
+      fName+="_"; fName+=id; fName+=".root";
+    } else {
+      fName+="ESDs.root";
+      fpFile=new TFile(fName, "RECREATE");
+    }
+  }
+  if (fpFile && !fpFile->IsZombie() && iResult>=0) {
+    if (!fpTree) {
+      fpTree=new TTree("esdTree", "Tree with HLT ESD objects");
+      if (!fpTree) {
+       iResult=-ENOMEM;
+      }
+    }
+    if (fpTree && iResult>=0) {
+      if (!fpEsd) {
+       // create the ESD structure for filling into the tree
+       fpEsd=new AliESDEvent;
+       if (fpEsd) {
+         fpEsd->CreateStdContent();
+         fpEsd->WriteToTree(fpTree);
+       } else {
+         iResult=-ENOMEM;
+       }
+      } else {
+       fpEsd->ResetStdContent();
+      }
+      if (eventno>=0) {
+       // synchronize and add empty events
+       for (int i=fpTree->GetEntries(); i<eventno; i++) {
+         fpTree->Fill();
+       }
+       if (fpTree->GetEntries()>eventno) {
+         HLTWarning("event %d ESD of type %s already written, skipping additional data block", eventno, AliHLTComponent::DataType2Text(fDt).c_str());
+       }
+      }
+      if (fpEsd) {
+       // we need to copy the ESD, I did not find an approptiate
+       // method, the workaround is to save the ESD in a temporary
+       // tree, read the content back into the ESD structure
+       // used for filling
+       TTree* dummy=new TTree("dummy","dummy");
+       if (dummy) {
+         pESD->WriteToTree(dummy);
+         dummy->Fill();
+         fpEsd->ReadFromTree(dummy);
+         dummy->GetEvent(0);
+         fpTree->Fill();
+         delete dummy;
+       } else {
+         iResult=-ENOMEM;
+       }
+      } else {
+       iResult=-ENOMEM;
+      }
+      if (iResult>=0) {
+       fpTree->Write("",TObject::kOverwrite);
+      }
+    }
+  }
+  return iResult;
+}
diff --git a/HLT/rec/AliHLTEsdManager.h b/HLT/rec/AliHLTEsdManager.h
new file mode 100644 (file)
index 0000000..f1469be
--- /dev/null
@@ -0,0 +1,108 @@
+//-*- Mode: C++ -*-
+// $Id$
+
+#ifndef ALIHLTESDMANAGER_H
+#define ALIHLTESDMANAGER_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   AliHLTEsdManager.h
+    @author Matthias Richter
+    @date   
+    @brief  Manager for merging and writing of HLT ESDs
+*/
+
+#include "AliHLTDataTypes.h"
+#include "AliHLTLogging.h"
+#include <vector>
+
+class AliESDEvent;
+class TTree;
+class TFile;
+
+/**
+ * @class AliHLTEsdManager
+ */
+class AliHLTEsdManager : public AliHLTLogging {
+ public:
+  /** constructor */
+  AliHLTEsdManager();
+  /** destructor */
+  virtual ~AliHLTEsdManager();
+
+  /**
+   * Convert data buffer to ESD.
+   * The buffer is supposed to describe a streamed AliESDEvent object.
+   * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
+   * where 'det' is derived from the data type origin. Each time the function is invoked
+   * a new event is created. Dummy events are added if the previous events did not contain
+   *
+   * @param pBuffer  [in] the data buffer
+   * @param size     [in] data buffer size
+   * @param dt       [in] data type of the block
+   * @param tgtesd   [out] optional target
+   * @param eventno  [in] optional event no
+   */
+  int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt,
+              AliESDEvent* tgtesd=NULL, int eventno=-1);
+
+ protected:
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTEsdManager(const AliHLTEsdManager&);
+  /** assignment operator prohibited */
+  AliHLTEsdManager& operator=(const AliHLTEsdManager&);
+
+  class AliHLTEsdListEntry : public AliHLTLogging {
+  public:
+    /** constructor */
+    AliHLTEsdListEntry(AliHLTComponentDataType dt);
+    /** copy constructor */
+    AliHLTEsdListEntry(const AliHLTEsdListEntry& src);
+    /** assignment operator */
+    AliHLTEsdListEntry& operator=(const AliHLTEsdListEntry& src);
+    /** destructor */
+    ~AliHLTEsdListEntry();
+
+    /**
+     * Write the ESD to the corresponding file.
+     * The tree is first synchronized with the eventno and additional empty
+     * events might be inserted if there was a gap. Since we are writing
+     * several files in parallel, we have to make sure that those files contain
+     * the same number of events.
+     * @param pESD        ESD to write
+     * @param eventno     optional event no for tree synchronization
+     */
+    int WriteESD(AliESDEvent* pESD, int eventno=-1);
+
+    bool operator==(AliHLTComponentDataType dt) const;
+
+  private:
+
+    /** root file name */
+    TString fName; //!transient
+    /** the root file for this esd */
+    TFile* fpFile; //!transient
+    /** the tree for this esd */
+    TTree* fpTree; //!transient
+    /** the esd to fill into the tree */
+    AliESDEvent* fpEsd; //!transient
+    /** data type of the corresponding block */
+    AliHLTComponentDataType fDt; //!transient
+  };
+
+  typedef vector<AliHLTEsdListEntry> AliHLTEsdList;
+
+  /**
+   * Find list entry for given data type
+   */
+  AliHLTEsdListEntry* Find(AliHLTComponentDataType dt) const;
+
+  /** the list of the ESDs */
+  AliHLTEsdList fESDs; //!transient
+
+  ClassDef(AliHLTEsdManager, 0)
+};
+#endif
diff --git a/HLT/rec/AliHLTOUTDigitReader.cxx b/HLT/rec/AliHLTOUTDigitReader.cxx
new file mode 100644 (file)
index 0000000..b5323c9
--- /dev/null
@@ -0,0 +1,213 @@
+// $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   AliHLTOUTDigitReader.cxx
+    @author Matthias Richter
+    @date   
+    @brief  HLTOUT data wrapper for simulated AliRoot HLT digit data.
+*/
+
+#include "AliHLTOUTDigitReader.h"
+#include "AliRawDataHeader.h"
+#include "AliDAQ.h"
+#include "TTree.h"
+#include "TFile.h"
+#include "TArrayC.h"
+#include "TBranch.h"
+#include "TString.h"
+#include <cassert>
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTOUTDigitReader)
+
+AliHLTOUTDigitReader::AliHLTOUTDigitReader(int event, AliHLTEsdManager* pEsdManager)
+  :
+  AliHLTOUTHomerCollection(event, pEsdManager),
+  fpDigitFile(NULL),
+  fpDigitTree(NULL),
+  fMinDDL(-1),
+  fMaxDDL(-1),
+  fppDigitArrays(NULL),
+  fpEquipments(NULL),
+  fNofDDLs(0),
+  fCurrent(-1)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTOUTDigitReader::~AliHLTOUTDigitReader()
+{
+  // see header file for class documentation
+  CloseTree();
+
+  if (fpDigitFile) {
+    fpDigitFile->Close();
+    delete fpDigitFile;
+    fpDigitFile=NULL;
+  }
+}
+
+Bool_t AliHLTOUTDigitReader::ReadNextData(UChar_t*& data)
+{
+  // see header file for class documentation
+  if (!fppDigitArrays && (!ReadArrays() || !fppDigitArrays))
+    return kFALSE;
+
+  if (fCurrent>=fNofDDLs)
+    return kFALSE;
+
+  while (++fCurrent<fNofDDLs) {
+    if (fMinDDL>-1 && fMinDDL>fpEquipments[fCurrent]) continue;
+    if (fMaxDDL>-1 && fMaxDDL<fpEquipments[fCurrent]) continue;
+    if (fppDigitArrays[fCurrent]->GetSize()>(int)sizeof(AliRawDataHeader)) {
+      data=reinterpret_cast<UChar_t*>(fppDigitArrays[fCurrent]->GetArray());
+      data+=sizeof(AliRawDataHeader);
+      return kTRUE;
+    }
+  }
+  return kFALSE;
+}
+
+int AliHLTOUTDigitReader::Reset()
+{
+  // see header file for class documentation
+  fCurrent=-1;
+  return 0;
+}
+
+int AliHLTOUTDigitReader::GetDataSize()
+{
+  // see header file for class documentation
+  if (fCurrent>=0 && fCurrent<fNofDDLs && fppDigitArrays) {
+    return fppDigitArrays[fCurrent]->GetSize()-sizeof(AliRawDataHeader);
+  }
+  return 0;
+}
+
+const AliRawDataHeader* AliHLTOUTDigitReader::GetDataHeader()
+{
+  // see header file for class documentation
+  if (fCurrent>=0 && fCurrent<fNofDDLs && fppDigitArrays) {
+    return reinterpret_cast<AliRawDataHeader*>(fppDigitArrays[fCurrent]->GetArray());
+  }
+  return NULL;
+}
+
+void AliHLTOUTDigitReader::SelectEquipment(int /*equipmentType*/, int minEquipmentId, int maxEquipmentId)
+{
+  // see header file for class documentation
+  fMinDDL=minEquipmentId;
+  fMaxDDL=maxEquipmentId;
+}
+
+int AliHLTOUTDigitReader::GetEquipmentId()
+{
+  // see header file for class documentation
+  if (fCurrent>=0 && fCurrent<fNofDDLs && fpEquipments) {
+    return fpEquipments[fCurrent];
+  }
+  return -1;
+}
+
+bool AliHLTOUTDigitReader::ReadArrays()
+{
+  // see header file for class documentation
+  bool result=false;
+
+  if (GetCurrentEventNo()<0) {
+    HLTWarning("no event selected, no data available");
+    return false;
+  }
+
+  if (!fpDigitFile) {
+    fpDigitFile=new TFile("HLT.Digits.root");
+  }
+  if (!fpDigitFile) return false;
+  if (fpDigitFile->IsZombie()) return false;
+
+  fpDigitFile->GetObject("rawhltout", fpDigitTree);
+  if (!fpDigitTree) {
+    return false;
+  }
+
+  vector<int> equipments;
+  int iTotal=0;
+  TIter iter(fpDigitTree->GetListOfBranches());
+  while (TBranch* br=(TBranch *)iter.Next()) {
+    iTotal++;
+    TString bname=br->GetName();
+    if (bname.BeginsWith("HLT_") && bname.EndsWith(".ddl")) {
+      bname.ReplaceAll("HLT_", "");
+      bname.ReplaceAll(".ddl", "");
+      if (bname.IsDigit()) {
+       int equipment=bname.Atoi();
+       int index=equipment-AliDAQ::DdlIDOffset("HLT");
+       if (index>=0 && strcmp(br->GetName(), AliDAQ::DdlFileName("HLT", index))==0) {
+         equipments.push_back(equipment);
+       } else {
+         HLTWarning("equipment mismatch: skipping id %d (out of range of HLT equipments)", equipment);
+       }
+      }
+    }
+  }
+  HLTDebug("found %d HLT branche(s) out of %d", equipments.size(), iTotal);
+
+  if (equipments.size()>0) {
+    fNofDDLs=equipments.size();
+    fpEquipments=new int[fNofDDLs];
+    fppDigitArrays=new TArrayC*[fNofDDLs];
+    if (fpEquipments && fppDigitArrays) {
+      memcpy(fpEquipments, &equipments[0], fNofDDLs*sizeof(int));
+      int i=0;
+      for (i=0; i<fNofDDLs; i++) {
+       fppDigitArrays[i]=NULL;
+       fpDigitTree->SetBranchAddress(AliDAQ::DdlFileName("HLT", fpEquipments[i]-AliDAQ::DdlIDOffset("HLT")), &fppDigitArrays[i]);
+      }
+      fpDigitTree->GetEvent(GetCurrentEventNo());
+      for (i=0; i<fNofDDLs; i++) {
+       if (fppDigitArrays[i]) {
+         HLTDebug("branch %s: %d byte(s)", AliDAQ::DdlFileName("HLT", fpEquipments[i]-AliDAQ::DdlIDOffset("HLT")), fppDigitArrays[i]);
+       }
+      }
+      result=true;
+    } else {
+      fNofDDLs=0;
+    }
+  }
+  return result;
+}
+
+int AliHLTOUTDigitReader::CloseTree()
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (fppDigitArrays) delete[] fppDigitArrays;
+  fppDigitArrays=NULL;
+  if (fpEquipments) delete[] fpEquipments;
+  fpEquipments=NULL;
+  if (fpDigitTree) delete fpDigitTree;
+  fpDigitTree=NULL;
+  fNofDDLs=0;
+  fCurrent=-1;
+
+  return iResult;
+}
diff --git a/HLT/rec/AliHLTOUTDigitReader.h b/HLT/rec/AliHLTOUTDigitReader.h
new file mode 100644 (file)
index 0000000..0d5756e
--- /dev/null
@@ -0,0 +1,89 @@
+//-*- Mode: C++ -*-
+// $Id$
+
+#ifndef ALIHLTOUTDIGITREADER_H
+#define ALIHLTOUTDIGITREADER_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   AliHLTOUTDigitReader.h
+    @author Matthias Richter
+    @date   
+    @brief  HLTOUT data wrapper for simulated AliRoot HLT digit data.
+*/
+
+#include "AliHLTOUTHomerCollection.h"
+
+class AliRawReader;
+class AliHLTHOMERReader;
+class TTree;
+class TFile;
+class TArrayC;
+
+/**
+ * @class AliHLTOUTDigitReader
+ * Handler of HLTOUT data for simulated HLT digit input.
+ */
+class AliHLTOUTDigitReader : public AliHLTOUTHomerCollection {
+ public:
+  /** standard constructor */
+  AliHLTOUTDigitReader(int event=-1, AliHLTEsdManager* pEsdManager=NULL);
+  /** destructor */
+  virtual ~AliHLTOUTDigitReader();
+
+ protected:
+  // interface functions of AliHLTOUTHomerCollection
+  Bool_t ReadNextData(UChar_t*& data);
+  int Reset();
+  int GetDataSize();
+  const AliRawDataHeader* GetDataHeader();
+  void SelectEquipment(int equipmentType, int minEquipmentId = -1, int maxEquipmentId = -1);
+  int GetEquipmentId();
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTOUTDigitReader(const AliHLTOUTDigitReader&);
+  /** assignment operator prohibited */
+  AliHLTOUTDigitReader& operator=(const AliHLTOUTDigitReader&);
+
+  /**
+   * Read the data from the root file and HLTOUT raw tree.
+   * Retrieve the number of branches and allocate arrays acording
+   * to that. After initialization of the arrays and variables, the
+   * event fEnvent is read.
+   */
+  bool ReadArrays();
+
+  /**
+   * Cleanup tree and data arrays.
+   */
+  int CloseTree();
+
+  /** the root file for the HLT 'digit' output */
+  TFile* fpDigitFile; //!transient
+
+  /** the tree for the HLT 'digit' output */
+  TTree* fpDigitTree; //!transient
+
+  /** min DDL id for equipment selection */
+  int fMinDDL; //!transient
+
+  /** max DDL id for equipment selection */
+  int fMaxDDL; //!transient
+
+  /** array of digit data read from tree */
+  TArrayC** fppDigitArrays; //!transient
+
+  /** array of equipment ids for the corresponding data blocks in fppDigitArrays */
+  int* fpEquipments; //!transient
+
+  /** number of DDL objects -> size of the arrays */
+  int fNofDDLs; //!transient
+
+  /** current position in the array */
+  int fCurrent; //!transient
+
+  ClassDef(AliHLTOUTDigitReader, 0)
+};
+#endif
diff --git a/HLT/rec/AliHLTOUTHomerCollection.cxx b/HLT/rec/AliHLTOUTHomerCollection.cxx
new file mode 100644 (file)
index 0000000..88ef869
--- /dev/null
@@ -0,0 +1,203 @@
+// $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   AliHLTOUTHomerCollection.cxx
+    @author Matthias Richter
+    @date   
+    @brief  General HLTOUT data collection.
+*/
+
+#include "AliHLTOUTHomerCollection.h"
+#include "AliHLTHOMERLibManager.h"
+#include "AliHLTHOMERReader.h"
+#include "AliRawDataHeader.h"
+#include "AliHLTEsdManager.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTOUTHomerCollection)
+
+AliHLTOUTHomerCollection::AliHLTOUTHomerCollection(int event, AliHLTEsdManager* pEsdManager)
+  :
+  AliHLTOUTHomerBuffer(NULL, 0),
+  fpCurrent(NULL),
+  fEvent(event),
+  fpEsdManager(pEsdManager)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+const int AliHLTOUTHomerCollection::fgkIdShift=16;
+
+AliHLTOUTHomerCollection::~AliHLTOUTHomerCollection()
+{
+  // see header file for class documentation
+  if (fpManager) {
+    if (fpCurrent) fpManager->DeleteReader(fpCurrent);
+    fpCurrent=NULL;
+  }
+}
+
+int AliHLTOUTHomerCollection::GenerateIndex()
+{
+  // see header file for class documentation
+  // step through all HLT ddls, create HOMER readers and
+  // scan data block
+  int iResult=0;
+  if (fpManager) {
+    Reset();
+    // there was a bug in AliDAQ returning the wrong equipment id
+    // for the HLT links. It has been fixed in the trunk on Feb 5th 2008
+    // and from v4-10-Release (Rev-02). For the moment we select directly
+    // to support older AliRoot versions
+    //Select("HLT");
+    SelectEquipment(0,7680, 7689);
+    UChar_t* pSrc=NULL;
+    while (ReadNextData(pSrc) && pSrc!=NULL && iResult>=0) {
+      AliHLTUInt32_t id=(GetEquipmentId());
+      unsigned int size=GetDataSize();
+
+      AliHLTHOMERReader* pReader=OpenReader(pSrc, size);
+
+      // we use the equipment id to identify the different homer blocks 
+      id<<=fgkIdShift;
+      if (pReader) {
+       iResult=ScanReader(pReader, id);
+       fpManager->DeleteReader(pReader);
+      }
+    }
+  } else {
+    iResult=-ENODEV;
+  }
+  return iResult;
+}
+
+int AliHLTOUTHomerCollection::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
+                                     AliHLTUInt32_t& size)
+{
+  // see header file for class documentation
+  int iResult=0;
+  pBuffer=NULL;
+  size=0;
+  if (fpManager) {
+    Int_t id = Int_t(index>>fgkIdShift);
+    AliHLTUInt32_t blockNo=index&((0x1<<fgkIdShift)-1);
+
+    // block from the same ddl requested?
+    if (fpCurrent && GetEquipmentId()!=id) {
+      fpManager->DeleteReader(fpCurrent);
+      fpCurrent=NULL;
+    }
+
+    // open ddl for equipment id and create HOMER reader
+    if (!fpCurrent) {
+      Reset();
+      SelectEquipment(-1, id, id);
+      UChar_t* pSrc=NULL;
+      if (ReadNextData(pSrc) && pSrc!=NULL) {
+       int srcSize=GetDataSize();
+       fpCurrent=OpenReader(pSrc, srcSize);
+       if (fpCurrent && fpCurrent->ReadNextEvent()!=0) {
+         iResult=-ENODATA;
+       }
+      } else {
+       iResult=-ENOSYS;
+      }
+    }
+
+    // get data
+    if (fpCurrent) {
+      AliHLTMonitoringReader* pReader=fpCurrent;
+      if ((pBuffer=static_cast<const AliHLTUInt8_t*>(pReader->GetBlockData(blockNo)))!=NULL) {
+       size=pReader->GetBlockDataLength(blockNo);
+      } else {
+       iResult=-ENOENT;
+      }
+    }
+  } else {
+    iResult=-ENODEV;
+  }
+  return iResult;
+}
+
+AliHLTHOMERReader* AliHLTOUTHomerCollection::OpenReader(UChar_t* pSrc, unsigned int size)
+{
+  // see header file for class documentation
+  unsigned int offset=sizeof(AliHLTOUTEventHeader);
+  const AliRawDataHeader* pCDH=GetDataHeader();
+  AliHLTUInt32_t id=(GetEquipmentId());
+  AliHLTUInt32_t statusFlags=pCDH->GetStatus();
+  AliHLTOUTEventHeader* pHLTHeader=reinterpret_cast<AliHLTOUTEventHeader*>(pSrc);
+
+  // consistency check for the block size
+  if (pHLTHeader->fLength!=size) {
+    HLTWarning("can not treat HLT data block %d: size mismatch, header %d, but buffer is %d", id, pHLTHeader->fLength, size);
+    return NULL;
+  }
+
+  // determine the offset of the homer block
+  // the HLT header is mandatory, HLT decision and HLT
+  // payload are optional. HLT decision is always before HLT
+  // payload if existent.
+  if (statusFlags&(0x1<<kCDHFlagsHLTDecision)) {
+    // the block contains HLT decision data, this is just
+    // skipped here
+    AliHLTUInt32_t* pDecisionLen=reinterpret_cast<AliHLTUInt32_t*>(pSrc+offset);
+    if ((*pDecisionLen)*sizeof(AliHLTUInt32_t)+offset<size) {
+      // the first 32bit word specifies the number of 32bit words in the
+      // decision block -> +1 for this length word
+      offset+=((*pDecisionLen)+1)*sizeof(AliHLTUInt32_t);
+    } else {
+      HLTWarning("size mismatch: HLT decision block bigger than total block length, skipping ...");
+      return NULL;
+    }
+  }
+
+  // check if there is payload
+  if (!(statusFlags&(0x1<<kCDHFlagsHLTPayload))) return NULL;
+
+  // continue if there is no data left in the buffer
+  if (offset>=size) {
+    HLTWarning("no HLT payload available, but bit is set, skipping ...");
+    return NULL;
+  }
+
+  // check for the HOME descriptor type id
+  AliHLTUInt64_t* pHomerDesc=reinterpret_cast<AliHLTUInt64_t*>(pSrc+offset);
+  if (*(pHomerDesc+kID_64b_Offset) != HOMER_BLOCK_DESCRIPTOR_TYPEID && 
+      ByteSwap64(*(pHomerDesc+kID_64b_Offset)) != HOMER_BLOCK_DESCRIPTOR_TYPEID) {
+    HLTWarning("format error: can not find HOMER block descriptor typid, skipping this data block");
+    return NULL;
+  }
+
+  return fpManager->OpenReaderBuffer(pSrc+offset, size-offset);
+}
+
+int AliHLTOUTHomerCollection::WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd) const
+{
+  // see header file for class documentation
+  if (!pBuffer && size<=0) return -EINVAL;
+  int iResult=0;
+  if (fpEsdManager) {
+    fpEsdManager->WriteESD(pBuffer, size, dt, tgtesd, GetCurrentEventNo());
+  }
+  return iResult;
+}
diff --git a/HLT/rec/AliHLTOUTHomerCollection.h b/HLT/rec/AliHLTOUTHomerCollection.h
new file mode 100644 (file)
index 0000000..e5e62c3
--- /dev/null
@@ -0,0 +1,126 @@
+//-*- Mode: C++ -*-
+// $Id$
+
+#ifndef ALIHLTOUTHOMERCOLLECTION_H
+#define ALIHLTOUTHOMERCOLLECTION_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   AliHLTOUTHomerCollection.h
+    @author Matthias Richter
+    @date   
+    @brief  General HLTOUT data collection.
+                                                                          */
+#include "AliHLTOUTHomerBuffer.h"
+
+class AliHLTHOMERReader;
+class AliRawDataHeader;
+class AliHLTEsdManager;
+
+/**
+ * @class AliHLTOUTHomerCollection
+ * Handler of HLTOUT data, base class for specific handlers for
+ * RawReader or Digit data.
+ */
+class AliHLTOUTHomerCollection : public AliHLTOUTHomerBuffer {
+ public:
+  /** constructor */
+  AliHLTOUTHomerCollection(int event=-1, AliHLTEsdManager* pEsdManager=NULL);
+  /** destructor */
+  virtual ~AliHLTOUTHomerCollection();
+
+ protected:
+  /**
+   * Read next data form the data source.
+   */
+  virtual Bool_t ReadNextData(UChar_t*& data)=0;
+
+  /**
+   * Reset data stream position.
+   * Reeading of data starts with the first data block.
+   */
+  virtual int Reset()=0;
+
+  /**
+   * Get size of the current data block.
+   */
+  virtual int GetDataSize()=0;
+
+  /**
+   * Get the header of the current data block
+   */
+  virtual const AliRawDataHeader* GetDataHeader()=0;
+
+  /**
+   * Select equipment for data readout.
+   */
+  virtual void SelectEquipment(int equipmentType, 
+                              int minEquipmentId = -1, 
+                              int maxEquipmentId = -1)=0;
+
+  /**
+   * Get equipment id of the current data block.
+   */
+  virtual int GetEquipmentId()=0;
+
+  /**
+   * Get the current event no.
+   * The event no is set during creation of the HLTOUT object.
+   * For the reconstruction it is taken from the ESD provided by the
+   * AliReconstruction framework AliESDEvent::GetEventNumberInFile
+   * @return event no or -1 if not set
+   */
+  int GetCurrentEventNo() const {return fEvent;}
+
+  // interface function of AliHLTOUT
+  int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTOUTHomerCollection(const AliHLTOUTHomerCollection&);
+  /** assignment operator prohibited */
+  AliHLTOUTHomerCollection& operator=(const AliHLTOUTHomerCollection&);
+
+  /**
+   * Generate the index of the HLTOUT data from the data buffer.
+   */
+  int GenerateIndex();
+
+  /**
+   * Get the data buffer
+   * @param index   [in]  index of the block
+   * @param pBuffer [out] buffer of the selected data block
+   * @param size    [out] size of the selected data block
+   */
+  int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
+                   AliHLTUInt32_t& size);
+
+  /**
+   * Open HOMER reader for the data buffer.
+   * The function expects the data buffer including all headers (CDH
+   * and HLTOUT header). The offset for the HLT payload is determined from
+   * the headers and the optional HLT decision data.
+   * @param pSrc    data buffer
+   * @param size    size of the buffer in byte
+   * @return instance of HOMER reader
+   */
+  AliHLTHOMERReader* OpenReader(UChar_t* pSrc, unsigned int size);
+
+  /** current instance of the HOMER reader */
+  AliHLTHOMERReader* fpCurrent;  //!transient
+
+  /** current event no */
+  int fEvent; //!transient
+
+  /** instance of the ESD manager for writing and merging */
+  AliHLTEsdManager* fpEsdManager; //!transient
+
+  /** DDL id offset shift for index
+   *  bit 16-31: DDL id, bit 0-15 block no
+   */
+  static const int fgkIdShift; //!transient
+  
+  ClassDef(AliHLTOUTHomerCollection, 0)
+};
+#endif
index 89821bff485a7918a539518beebe31d6e2cd2dac..e63b0e8383dc8f899346246f24d5c961cdfbd0ae 100644 (file)
@@ -1,45 +1,37 @@
 // $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   AliHLTOUTRawReader.cxx
     @author Matthias Richter
     @date   
-    @brief  HLTOUT data wrapper for AliRawReader.                         */
-
-// 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  HLTOUT data wrapper for AliRawReader.                         
+*/
 
 #include "AliHLTOUTRawReader.h"
-#include "AliHLTHOMERLibManager.h"
 #include "AliRawReader.h"
-#include "AliHLTHOMERReader.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTOUTRawReader)
 
-AliHLTOUTRawReader::AliHLTOUTRawReader(AliRawReader* pRawreader)
+AliHLTOUTRawReader::AliHLTOUTRawReader(AliRawReader* pRawreader, int event, AliHLTEsdManager* pEsdManager)
   :
-  AliHLTOUTHomerBuffer(NULL, 0),
-  fpRawreader(pRawreader),
-  fpCurrent(NULL)
+  AliHLTOUTHomerCollection(event, pEsdManager),
+  fpRawreader(pRawreader)
 {
   // see header file for class documentation
   // or
@@ -48,148 +40,48 @@ AliHLTOUTRawReader::AliHLTOUTRawReader(AliRawReader* pRawreader)
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 }
 
-const int AliHLTOUTRawReader::fgkIdShift=16;
-
 AliHLTOUTRawReader::~AliHLTOUTRawReader()
 {
   // see header file for class documentation
-  if (fpManager) {
-    if (fpCurrent) fpManager->DeleteReader(fpCurrent);
-    fpCurrent=NULL;
-  }
 }
 
-int AliHLTOUTRawReader::GenerateIndex()
+Bool_t AliHLTOUTRawReader::ReadNextData(UChar_t*& data)
 {
   // see header file for class documentation
-  // step through all HLT ddls, create HOMER readers and
-  // scan data block
-  int iResult=0;
-  if (fpRawreader && fpManager) {
-    fpRawreader->Reset();
-    // there was a bug in AliDAQ returning the wrong equipment id
-    // for the HLT links. It has been fixed in the trunk on Feb 5th 2008
-    // and from v4-10-Release (Rev-02). For the moment we select directly
-    // to support older AliRoot versions
-    //fpRawreader->Select("HLT");
-    fpRawreader->SelectEquipment(0,7680, 7689);
-    UChar_t* pSrc=NULL;
-    while (fpRawreader->ReadNextData(pSrc) && pSrc!=NULL && iResult>=0) {
-      AliHLTUInt32_t id=(fpRawreader->GetEquipmentId());
-      unsigned int size=fpRawreader->GetDataSize();
-
-      AliHLTHOMERReader* pReader=OpenReader(pSrc, size);
-
-      // we use the equipment id to identify the different homer blocks 
-      id<<=fgkIdShift;
-      if (pReader) {
-       iResult=ScanReader(pReader, id);
-       fpManager->DeleteReader(pReader);
-      }
-    }
-  } else {
-    iResult=-ENODEV;
-  }
-  return iResult;
+  if (!fpRawreader) return kFALSE;
+  return fpRawreader->ReadNextData(data);
 }
 
-int AliHLTOUTRawReader::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
-                                     AliHLTUInt32_t& size)
+int AliHLTOUTRawReader::Reset()
 {
   // see header file for class documentation
-  int iResult=0;
-  pBuffer=NULL;
-  size=0;
-  if (fpManager) {
-    Int_t id = Int_t(index>>fgkIdShift);
-    AliHLTUInt32_t blockNo=index&((0x1<<fgkIdShift)-1);
-
-    // block from the same ddl requested?
-    if (fpCurrent && fpRawreader->GetEquipmentId()!=id) {
-      fpManager->DeleteReader(fpCurrent);
-      fpCurrent=NULL;
-    }
-
-    // open ddl for equipment id and create HOMER reader
-    if (!fpCurrent) {
-      fpRawreader->Reset();
-      fpRawreader->SelectEquipment(-1, id, id);
-      UChar_t* pSrc=NULL;
-      if (fpRawreader->ReadNextData(pSrc) && pSrc!=NULL) {
-       int srcSize=fpRawreader->GetDataSize();
-       fpCurrent=OpenReader(pSrc, srcSize);
-       if (fpCurrent && fpCurrent->ReadNextEvent()!=0) {
-         iResult=-ENODATA;
-       }
-      } else {
-       iResult=-ENOSYS;
-      }
-    }
-
-    // get data
-    if (fpCurrent) {
-      AliHLTMonitoringReader* pReader=fpCurrent;
-      if ((pBuffer=static_cast<const AliHLTUInt8_t*>(pReader->GetBlockData(blockNo)))!=NULL) {
-       size=pReader->GetBlockDataLength(blockNo);
-      } else {
-       iResult=-ENOENT;
-      }
-    }
-  } else {
-    iResult=-ENODEV;
-  }
-  return iResult;
+  if (fpRawreader) return fpRawreader->Reset();
+  return 0;
 }
 
-AliHLTHOMERReader* AliHLTOUTRawReader::OpenReader(UChar_t* pSrc, unsigned int size)
+int AliHLTOUTRawReader::GetDataSize()
 {
   // see header file for class documentation
-  unsigned int offset=sizeof(AliHLTOUTEventHeader);
-  const AliRawDataHeader* pCDH=fpRawreader->GetDataHeader();
-  AliHLTUInt32_t id=(fpRawreader->GetEquipmentId());
-  AliHLTUInt32_t statusFlags=pCDH->GetStatus();
-  AliHLTOUTEventHeader* pHLTHeader=reinterpret_cast<AliHLTOUTEventHeader*>(pSrc);
-
-  // consistency check for the block size
-  if (pHLTHeader->fLength!=size) {
-    HLTWarning("can not treat HLT data block %d: size missmatch, header %d, but buffer is %d", id, pHLTHeader->fLength, size);
-    return NULL;
-  }
-
-  // determine the offset of the homer block
-  // the HLT header is mandatory, HLT decision and HLT
-  // payload are optional. HLT decision is always before HLT
-  // payload if existent.
-  if (statusFlags&(0x1<<kCDHFlagsHLTDecision)) {
-    // the block contains HLT decision data, this is just
-    // skipped here
-    AliHLTUInt32_t* pDecisionLen=reinterpret_cast<AliHLTUInt32_t*>(pSrc+offset);
-    if ((*pDecisionLen)*sizeof(AliHLTUInt32_t)+offset<size) {
-      // the first 32bit word specifies the number of 32bit words in the
-      // decision block -> +1 for this length word
-      offset+=((*pDecisionLen)+1)*sizeof(AliHLTUInt32_t);
-    } else {
-      HLTWarning("size missmatch: HLT decision block bigger than total block length, skipping ...");
-      return NULL;
-    }
-  }
-
-  // check if there is payload
-  if (!(statusFlags&(0x1<<kCDHFlagsHLTPayload))) return NULL;
+  if (fpRawreader) return fpRawreader->GetDataSize();
+  return 0;
+}
 
-  // continue if there is no data left in the buffer
-  if (offset>=size) {
-    HLTWarning("no HLT payload available, but bit is set, skipping ...");
-    return NULL;
-  }
+const AliRawDataHeader* AliHLTOUTRawReader::GetDataHeader()
+{
+  // see header file for class documentation
+  if (fpRawreader) return fpRawreader->GetDataHeader();
+  return NULL;
+}
 
-  // check for the HOME descriptor type id
-  AliHLTUInt64_t* pHomerDesc=reinterpret_cast<AliHLTUInt64_t*>(pSrc+offset);
-  if (*(pHomerDesc+kID_64b_Offset) != HOMER_BLOCK_DESCRIPTOR_TYPEID && 
-      ByteSwap64(*(pHomerDesc+kID_64b_Offset)) != HOMER_BLOCK_DESCRIPTOR_TYPEID) {
-    HLTWarning("format error: can not find HOMER block descriptor typid, skipping this data block");
-    return NULL;
-  }
+void AliHLTOUTRawReader::SelectEquipment(int equipmentType, int minEquipmentId, int maxEquipmentId)
+{
+  // see header file for class documentation
+  if (fpRawreader) fpRawreader->SelectEquipment(equipmentType, minEquipmentId, maxEquipmentId);
+}
 
-  return fpManager->OpenReaderBuffer(pSrc+offset, size-offset);
+int AliHLTOUTRawReader::GetEquipmentId()
+{
+  // see header file for class documentation
+  if (fpRawreader) return fpRawreader->GetEquipmentId();
+  return -1;
 }
index bc0b6302e65ebebe9eec7440f2078d7719e82513..27dc223d5f56d2de4f143f86d502f0df12c8f564 100644 (file)
@@ -3,22 +3,17 @@
 
 #ifndef ALIHLTOUTRAWREADER_H
 #define ALIHLTOUTRAWREADER_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                               */
+//* 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   AliHLTOUTRawReader.h
     @author Matthias Richter
     @date   
     @brief  HLTOUT data wrapper for AliRawReader.
-                                                                          */
-// see below for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+*/
 
-#include "AliHLTOUTHomerBuffer.h"
+#include "AliHLTOUTHomerCollection.h"
 
 class AliRawReader;
 class AliHLTHOMERReader;
@@ -27,14 +22,21 @@ class AliHLTHOMERReader;
  * @class AliHLTOUTRawReader
  * Handler of HLTOUT data for AliRawReader input.
  */
-class AliHLTOUTRawReader : public AliHLTOUTHomerBuffer {
+class AliHLTOUTRawReader : public AliHLTOUTHomerCollection {
  public:
   /** constructor */
-  AliHLTOUTRawReader(AliRawReader* pRawReader);
+  AliHLTOUTRawReader(AliRawReader* pRawReader, int event=-1, AliHLTEsdManager* pEsdManager=NULL);
   /** destructor */
   virtual ~AliHLTOUTRawReader();
 
  protected:
+  // interface functions of AliHLTOUTHomerCollection
+  Bool_t ReadNextData(UChar_t*& data);
+  int Reset();
+  int GetDataSize();
+  const AliRawDataHeader* GetDataHeader();
+  void SelectEquipment(int equipmentType, int minEquipmentId = -1, int maxEquipmentId = -1);
+  int GetEquipmentId();
 
  private:
   /** standard constructor prohibited */
@@ -44,42 +46,9 @@ class AliHLTOUTRawReader : public AliHLTOUTHomerBuffer {
   /** assignment operator prohibited */
   AliHLTOUTRawReader& operator=(const AliHLTOUTRawReader&);
 
-  /**
-   * Generate the index of the HLTOUT data from the data buffer.
-   */
-  int GenerateIndex();
-
-  /**
-   * Get the data buffer
-   * @param index   [in]  index of the block
-   * @param pBuffer [out] buffer of the selected data block
-   * @param size    [out] size of the selected data block
-   */
-  int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
-                   AliHLTUInt32_t& size);
-
-  /**
-   * Open HOMER reader for the data buffer.
-   * The function expects the data buffer including all headers (CDH
-   * and HLTOUT header). The offset for the HLT payload is determined from
-   * the headers and the optional HLT decision data.
-   * @param pSrc    data buffer
-   * @param size    size of the buffer in byte
-   * @return instance of HOMER reader
-   */
-  AliHLTHOMERReader* OpenReader(UChar_t* pSrc, unsigned int size);
-
   /** the rawreader */
   AliRawReader* fpRawreader; //!transient
 
-  /** current instance of the HOMER reader */
-  AliHLTHOMERReader* fpCurrent;  //!transient
-
-  /** DDL id offset shift for index
-   *  bit 16-31: DDL id, bit 0-15 block no
-   */
-  static const int fgkIdShift; //!transient
-  
-  ClassDef(AliHLTOUTRawReader, 0)
+  ClassDef(AliHLTOUTRawReader, 1)
 };
 #endif
index 59d0623895f9be77df43df1d5dafde54478a9730..ea1036bfd9b04e06330b1a0ca40359c807329542 100644 (file)
@@ -1,20 +1,20 @@
 // $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   AliHLTReconstructor.cxx
     @author Matthias Richter
 #include <TObjString.h>
 #include "AliHLTReconstructor.h"
 #include "AliLog.h"
+#include "AliESDEvent.h"
 #include "AliHLTSystem.h"
+#include "AliHLTOUTRawReader.h"
+#include "AliHLTOUTDigitReader.h"
+#include "AliHLTEsdManager.h"
 
 ClassImp(AliHLTReconstructor)
 
 AliHLTReconstructor::AliHLTReconstructor()
   : 
   AliReconstructor(),
-  AliHLTReconstructorBase()
+  AliHLTReconstructorBase(),
+  fFctProcessHLTOUT(NULL),
+  fpEsdManager(NULL)
 { 
   //constructor
 }
@@ -49,6 +55,9 @@ AliHLTReconstructor::~AliHLTReconstructor()
       pSystem->Reconstruct(0, NULL, NULL);
     }
   }
+
+  if (fpEsdManager) delete fpEsdManager;
+  fpEsdManager=NULL;
 }
 
 void AliHLTReconstructor::Init()
@@ -125,28 +134,33 @@ void AliHLTReconstructor::Init()
       return;
     }
   }
+
+  gSystem->Load("libHLTinterface.so");
+  fFctProcessHLTOUT=gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
+
+  fpEsdManager=new AliHLTEsdManager;
 }
 
 void AliHLTReconstructor::Reconstruct(AliRawReader* /*rawReader*/, TTree* /*clustersTree*/) const 
 {
   // reconstruction of real data without writing of ESD
-
-  // all reconstruction has been moved to FillESD
-//   int iResult=0;
-//   if (fpSystem) {
-//     if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
-//       AliError("HLT system in error state");
-//       return;
-//     }
-//     if ((iResult=fpSystem->Reconstruct(1, NULL, rawReader))>=0) {
-//     }
-//   }
+  // For each event, HLT reconstruction chains can be executed and
+  // added to the existing HLTOUT data
+  // The HLTOUT data is finally processed in FillESD
+  AliHLTSystem* pSystem=GetInstance();
 }
 
 void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/, 
                                  AliESDEvent* esd) const
 {
   // reconstruct real data and fill ESD
+  if (!rawReader || !esd) {
+    AliError("missing raw reader or esd object");
+    return;
+  }
+
+  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  // code needs to be moved back to Reconstruct as soon es HLT loader is implemented
   int iResult=0;
   AliHLTSystem* pSystem=GetInstance();
   if (pSystem) {
@@ -159,7 +173,26 @@ void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree
       return;
     }
     if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
-      pSystem->FillESD(-1, NULL, esd);
+    }
+  }
+  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  if (pSystem) {
+    if (pSystem->CheckStatus(AliHLTSystem::kError)) {
+      AliError("HLT system in error state");
+      return;
+    }
+    if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
+      AliError("HLT system in wrong state");
+      return;
+    }
+    pSystem->FillESD(-1, NULL, esd);
+
+    AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
+    if (pHLTOUT) {
+      ProcessHLTOUT(pHLTOUT, esd);
+    } else {
+      AliError("error creating HLTOUT handler");
     }
   }
 }
@@ -172,7 +205,7 @@ void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTr
   //AliReconstructor::Reconstruct(digitsTree,clustersTree);
 }
 
-void AliHLTReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, AliESDEvent* esd) const
+void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
 {
   // reconstruct simulated data and fill ESD
 
@@ -180,7 +213,8 @@ void AliHLTReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, AliESD
   // for now it's only an user failure condition as he tries to run HLT reconstruction
   // on simulated data 
   TString option = GetOption();
-  if (!option.IsNull()) {
+  if (!option.IsNull() && 
+      (option.Contains("config=") || option.Contains("chains="))) {
     AliWarning(Form("HLT reconstruction of simulated data takes place in AliSimulation\n"
                    "        /***  run macro *****************************************/\n"
                    "        AliSimulation sim;\n"
@@ -192,5 +226,46 @@ void AliHLTReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, AliESD
                    "        sim.Run();\n"
                    "        /*********************************************************/", option.Data()));
   }
-  AliReconstructor::FillESD(digitsTree,clustersTree,esd);
+  AliHLTSystem* pSystem=GetInstance();
+  if (pSystem) {
+    if (pSystem->CheckStatus(AliHLTSystem::kError)) {
+      AliError("HLT system in error state");
+      return;
+    }
+    if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
+      AliError("HLT system in wrong state");
+      return;
+    }
+
+    AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
+    if (pHLTOUT) {
+      ProcessHLTOUT(pHLTOUT, esd);
+    } else {
+      AliError("error creating HLTOUT handler");
+    }
+  }
+}
+
+void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) const
+{
+  // treatmen of simulated or real HLTOUT data
+  if (!pHLTOUT) return;
+  AliHLTSystem* pSystem=GetInstance();
+  if (!pSystem) {
+    AliError("error getting HLT system instance");
+    return;
+  }
+
+  if (pHLTOUT->Init()<0) {
+    AliError("error : initialization of HLTOUT handler failed");
+    return;
+  }
+
+  if (fFctProcessHLTOUT) {
+    typedef int (*AliHLTSystemProcessHLTOUT)(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd);
+    AliHLTSystemProcessHLTOUT pFunc=(AliHLTSystemProcessHLTOUT)fFctProcessHLTOUT;
+    if ((pFunc)(pSystem, pHLTOUT, esd)<0) {
+      AliError("error processing HLTOUT");
+    }
+  }
 }
index c423a15239602ed6b6433e32cdc25199a83fa668..3fad1a6fb32e32092116da5a3cdeddcda7f762f0 100644 (file)
@@ -2,21 +2,15 @@
 
 #ifndef ALIHLTRECONSTRUCTOR_H
 #define ALIHLTRECONSTRUCTOR_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                               */
+//* 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   AliHLTReconstructor.h
     @author Matthias Richter
     @date   
     @brief  Binding class for HLT simulation in AliRoot
-
-// see below for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
-                                                                          */
+*/
 
 #include "AliReconstructor.h"
 #include "AliHLTReconstructorBase.h"
@@ -24,6 +18,8 @@
 class AliHLTSystem;
 class AliRawReader;
 class AliESDEvent;
+class AliHLTOUT;
+class AliHLTEsdManager;
 
 /**
  * @class AliHLTReconstructor
@@ -70,6 +66,9 @@ public:
    * The function forwards to the default bahavior of AliReconstructor but gives
    * a warning if there were options set, i.e. the user runs customized
    * reconstruction.
+   *
+   * @note HLT reconstruction on simulated data is processed at the end of
+   * simulation. <br>
    */
   void Reconstruct(TTree* digitsTree, TTree* clustersTree) const;
 
@@ -81,29 +80,43 @@ public:
   void Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const;
 
   /**
-   * This function is purely for simulated data and not applicable for HLT.
-   * HLT reconstruction on simulated data is processed at the end of
-   * simulation. <br>
-   * The function forwards to the default bahavior of AliReconstructor but gives
-   * a warning if there were options set, i.e. the user runs customized
-   * reconstruction.
+   * This function treats the simulated HLTOUT data.
+   * Opens a handler for simulated HLTOUT data and forwards to ::ProcessHLTOUT.
    */
   void FillESD(TTree* digitsTree, TTree* clustersTree, AliESDEvent* esd) const;
 
   /**
-   * Fill the ESD from RAW data.
-   * This is the main entry for HLT reconstruction of RAW data. It performs both
-   * the analysis by the defined chains and the filling of the ESD.
+   * Process the raw HLTOUT data and fill ESD.
+   * Opens a handler for raw HLTOUT data and forwards to ::ProcessHLTOUT.
    */
   void FillESD(AliRawReader* rawReader, TTree* clustersTree, AliESDEvent* esd) const;
 
+  /**
+   * Process HLTOUT data and fill ESD.
+   * This is the final treatment of the HLTOUT data, either simulated or real.
+   * HLTOUT data is stored in HOMER format, the AliHLTOUT object provides the interface
+   * to the individual data blocks.
+   *
+   * During reconstruction (::Reconstruct), module or user defined chains can be
+   * processed and may add additional data to the HLTOUT object. This data is then
+   * treated in the same way.
+   */
+  void ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) const;
+
 private:
   /** copy constructor prohibited */
   AliHLTReconstructor(const AliHLTReconstructor& src);
   /** assignment operator prohibited */
   AliHLTReconstructor& operator=(const AliHLTReconstructor& src);
 
-  ClassDef(AliHLTReconstructor, 4)   // class for the HLT reconstruction
+  /** function pointer: processing of HLTOUT data */
+  void* fFctProcessHLTOUT; //!transient
+
+  /** ESD manger instance for this reconstruction */
+  AliHLTEsdManager* fpEsdManager; //!transient
+
+  ClassDef(AliHLTReconstructor, 5)   // class for the HLT reconstruction
+
 };
 
 typedef AliHLTReconstructor AliL3Reconstructor; // for backward compatibility
index eab95e31bd062c9620e365e9a11979881b72a6ca..5d43774b473db571a6a9de6a3461550d3b647c48 100644 (file)
@@ -11,7 +11,7 @@ EXTRA_DIST                    =
 lib_LTLIBRARIES                        =  libHLTrec.la
 
 # version info for the library
-LIBRARY_VERSION                        = "$(LIBHLTREC_VERSION):0:0"
+LIBRARY_VERSION                        = "$(LIBHLTREC_VERSION):0:1"
 
 # MODDIR is set by the AliRoot build system and denotes the topdir
 # of the module, we must set it since the package definition libHLTrec.pkg
index dabafe584726bdff53bf5190835395fc4a138a72..fb3c306c013c63ace8c944c8b41f9aa2c374c748 100644 (file)
@@ -1,20 +1,20 @@
 // $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   AliHLTOUTComponent.cxx
     @author Matthias Richter
     @brief  The HLTOUT data sink component similar to HLTOUT nodes
 */
 
-// 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 __GNUC__>= 3
 using namespace std;
 #endif
@@ -42,6 +36,9 @@ using namespace std;
 #include "AliRawDataHeader.h" // Common Data Header 
 #include <TDatime.h> // seed for TRandom
 #include <TRandom.h> // random int generation for DDL no
+#include <TFile.h>
+#include <TTree.h>
+#include <TArrayC.h>
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTOUTComponent)
@@ -53,7 +50,10 @@ AliHLTOUTComponent::AliHLTOUTComponent()
   fNofDDLs(10),
   fIdFirstDDL(7680), // 0x1e<<8
   fBuffer(),
-  fpLibManager(NULL)
+  fpLibManager(NULL),
+  fpDigitFile(NULL),
+  fpDigitTree(NULL),
+  fppDigitArrays(NULL)
 {
   // see header file for class documentation
   // or
@@ -142,7 +142,7 @@ int AliHLTOUTComponent::DoInit( int argc, const char** argv )
        HLTDebug("HOMER writer %p added", pWriter);
        fWriters.push_back(pWriter);
       } else {
-       HLTError("can nor open HOMER writer");
+       HLTError("can not open HOMER writer");
        iResult=-ENODEV;
        break;
       }
@@ -170,6 +170,25 @@ int AliHLTOUTComponent::DoDeinit()
       element=fWriters.erase(element);
     }
   }
+
+  if (fpDigitTree) {
+    delete fpDigitTree;
+    fpDigitTree=NULL;
+  }
+
+  if (fpDigitFile) {
+    fpDigitFile->Close();
+    delete fpDigitFile;
+    fpDigitFile=NULL;
+  }
+
+  if (fppDigitArrays) {
+    for (int i=0; i<fNofDDLs; i++) {
+      if (fppDigitArrays[i]) delete fppDigitArrays[i];
+    }
+    delete[] fppDigitArrays;
+    fppDigitArrays=NULL;
+  }
   
   return iResult;
 }
@@ -197,7 +216,7 @@ int AliHLTOUTComponent::DumpEvent( const AliHLTComponentEventData& evtData,
       memcpy(&id, blocks[n].fDataType.fID, sizeof(homer_uint64));
       memcpy(((AliHLTUInt8_t*)&origin)+sizeof(homer_uint32), blocks[n].fDataType.fOrigin, sizeof(homer_uint32));
       homerDescriptor.SetType(AliHLTOUT::ByteSwap64(id));
-      homerDescriptor.SetSubType1(AliHLTOUT::ByteSwap32(origin));
+      homerDescriptor.SetSubType1(AliHLTOUT::ByteSwap64(origin));
       homerDescriptor.SetSubType2(blocks[n].fSpecification);
       homerDescriptor.SetBlockSize(blocks[n].fSize);
       int writerNo=ShuffleWriters(fWriters, blocks[n].fSize);
@@ -241,12 +260,13 @@ int AliHLTOUTComponent::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEven
     int bufferSize=0;
     
     if ((bufferSize=FillOutputBuffer(eventNo, fWriters[*ddlno], pBuffer))>0) {
-      if (fgOptions&kWriteDigits) WriteDigits(eventNo, runLoader, *ddlno, pBuffer, bufferSize);
+      if (fgOptions&kWriteDigits) WriteDigitArray(*ddlno, pBuffer, bufferSize);
       if (fgOptions&kWriteRawFiles) WriteRawFile(eventNo, runLoader, *ddlno, pBuffer, bufferSize);
     }
     fWriters[*ddlno]->Clear();
     ddlno++;
   }
+  if (fgOptions&kWriteDigits) WriteDigits(eventNo, runLoader);
   return iResult;
 }
 
@@ -334,10 +354,67 @@ int AliHLTOUTComponent::FillOutputBuffer(int eventNo, AliHLTMonitoringWriter* pW
   return iResult;
 }
 
-int AliHLTOUTComponent::WriteDigits(int /*eventNo*/, AliRunLoader* /*runLoader*/, int /*hltddl*/, const AliHLTUInt8_t* /*pBuffer*/, unsigned int /*bufferSize*/)
+int AliHLTOUTComponent::WriteDigitArray(int hltddl, const AliHLTUInt8_t* pBuffer, unsigned int bufferSize)
+{
+  // see header file for class documentation
+  int iResult=0;
+  assert(hltddl<fNofDDLs);
+  if (hltddl>=fNofDDLs) return -ERANGE;
+
+  if (!fppDigitArrays) {
+    fppDigitArrays=new TArrayC*[fNofDDLs];
+    if (fppDigitArrays) {
+      for (int i=0; i<fNofDDLs; i++) {
+       fppDigitArrays[i]=new TArrayC(0);
+      }
+    }
+  }
+  if (fppDigitArrays && fppDigitArrays[hltddl]) {
+    fppDigitArrays[hltddl]->Set(bufferSize, reinterpret_cast<const Char_t*>(pBuffer));
+  } else {
+    iResult=-ENOMEM;    
+  }
+  return iResult;
+}
+
+int AliHLTOUTComponent::WriteDigits(int /*eventNo*/, AliRunLoader* /*runLoader*/)
 {
   // see header file for class documentation
   int iResult=0;
+  const char* digitFileName="HLT.Digits.root";
+  if (!fpDigitFile) {
+    fpDigitFile=new TFile(digitFileName, "RECREATE");
+  }
+  if (fpDigitFile && !fpDigitFile->IsZombie()) {
+    if (!fpDigitTree) {
+      fpDigitTree=new TTree("rawhltout","HLTOUT raw data");
+      if (fpDigitTree && fppDigitArrays) {
+       for (int i=0; i<fNofDDLs; i++) {
+         const char* branchName=AliDAQ::DdlFileName("HLT", i);
+         if (fppDigitArrays[i]) fpDigitTree->Branch(branchName, "TArrayC", &fppDigitArrays[i], 32000/*just as the default*/, 0);
+       }
+      }
+    }
+    if (fpDigitTree) {
+      int res=fpDigitTree->Fill();
+      HLTDebug("writing digit tree: %d", res);
+      fpDigitFile->cd();
+      res=fpDigitTree->Write("",TObject::kOverwrite);
+      HLTDebug("writing digit tree: %d", res);
+      if (fppDigitArrays) for (int i=0; i<fNofDDLs; i++) {
+       if (fppDigitArrays[i]) fppDigitArrays[i]->Set(0);
+      }
+    }
+  } else {
+    const char* errorMsg="";
+    if (GetEventCount()==5) {
+      errorMsg=" (suppressing further error messages)";
+    }
+    if (GetEventCount()<5) {
+      HLTError("can not open HLT digit file %s%s", digitFileName, errorMsg);
+    }
+    iResult=-EBADF;
+  }
   return iResult;
 }
 
index 408f9452687e11fb7f17f3a92e15f77610faea16..b81eee90ce5722f0613530f6b9ea9c3a664cc97a 100644 (file)
@@ -2,9 +2,9 @@
 
 #ifndef ALIHLTOUTCOMPONENT_H
 #define ALIHLTOUTCOMPONENT_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                               */
+//* 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   AliHLTOUTComponent.h
     @author Matthias Richter
@@ -22,6 +22,8 @@
 
 class AliHLTHOMERLibManager;
 class AliHLTMonitoringWriter;
+class TFile;
+class TTree;
 typedef vector<AliHLTMonitoringWriter*> AliHLTMonitoringWriterPVector;
 
 /**
@@ -151,16 +153,21 @@ class AliHLTOUTComponent : public AliHLTOfflineDataSink  {
    */
   int FillOutputBuffer(int eventNo, AliHLTMonitoringWriter* pWriter, const AliHLTUInt8_t* &pBuffer);
 
+  /**
+   * Write data for a DDL link.
+   * @param hltddl     Number of DDL link within the range of HLT
+   * @param pBuffer    buffer to write
+   * @param bufferSize size of the buffer
+   */
+  int WriteDigitArray(int hltddl, const AliHLTUInt8_t* pBuffer, unsigned int bufferSize);
+
   /**
    * Write the digits for one DDL
    * @param eventNo    number of the event
    * @param runLoader  AliRoot run loader instance
-   * @param hltddl     Number of DDL link within the range of HLT
-   * @param pBuffer    buffer to write
-   * @param size       size of the buffer
    * @return neg. error if failed
    */
-  int WriteDigits(int eventNo, AliRunLoader* runLoader, int hltddl, const AliHLTUInt8_t* pBuffer, unsigned int size);
+  int WriteDigits(int eventNo, AliRunLoader* runLoader);
 
   /**
    * Write the raw file for one DDL
@@ -191,6 +198,15 @@ class AliHLTOUTComponent : public AliHLTOfflineDataSink  {
   /** global options for all instances */
   static int fgOptions; //! transient
 
-  ClassDef(AliHLTOUTComponent, 1)
+  /** the root file for the HLT 'digit' output */
+  TFile* fpDigitFile; //!transient
+
+  /** the tree for the HLT 'digit' output */
+  TTree* fpDigitTree; //!transient
+
+  /** array of TArrayC output buffers and branches */
+  TArrayC** fppDigitArrays; //!transient
+
+  ClassDef(AliHLTOUTComponent, 2)
 };
 #endif
index ebb196cc2b5d8ed9d0e01ea4f5fc88dad5356b36..252a8903d96abdce4db07e9b770b2e034a4f4374 100644 (file)
@@ -1,20 +1,20 @@
 // $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   AliHLTSimulation.cxx
     @author Matthias Richter
@@ -122,7 +122,7 @@ int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
            int count=0;
            for (; fpRawReader->NextEvent(); count++);
            if (count!=pRunLoader->GetNumberOfEvents()) {
-             AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader", 
+             AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader", 
                            pRunLoader->GetNumberOfEvents(), count));
              count=0;
            }
@@ -184,7 +184,7 @@ int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
     fpSystem->FillESD(0, pRunLoader, NULL);
     for (int i=1; i<nEvents; i++) {
       if (fpRawReader && !fpRawReader->NextEvent()) {
-       AliError("missmatch in event count, rawreader corrupted");
+       AliError("mismatch in event count, rawreader corrupted");
        break;
       }
       fpSystem->Reconstruct(1, pRunLoader, fpRawReader);