ROOT logo
//-*- 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 "TString.h"

class AliESDEvent;

/**
 * @class AliHLTEsdManager
 * Tool to write and merge HLT ESD objects.
 *
 * HLT components can produce ESD output. The ESD objects are sent via
 * a TMessage like mechanism as part of the HLTOUT data. This class retrieves
 * streamed AliESDEvent objects from an HLT output block. An ESD object can be
 * copied to a global ESD provided by the caller or to files. The name of the
 * ROOT files follows the scheme AliHLTDETESDs.root where DET denotes a detector.
 * E.g. the ESD from a data block of type {ESD_TREE,TPC} will be added to the
 * file AliHLTTPCESDs.root.
 *
 * For the sake of library (in)dependencies, the concrete implementation of
 * the AliHLTEsdManager is separated from the libHLTbase class as this would
 * introduce dependencies to AliRoot libraries. The user does not notice the
 * handling apart from the fact that an instance can not be created and
 * deleted directly. Instead 
 * <pre>
 *   AliHLTEsdManager* pManager=AliHLTEsdManager::New();
 *   // ....
 *   AliHLTEsdManager::Delete(pManager);
 * </pre>
 * must be used.
 *
 * @ingroup alihlt_aliroot_reconstruction
 */
class AliHLTEsdManager : public AliHLTLogging {
 public:
  /** create an instance of the manager */
  static AliHLTEsdManager* New();
  /** delete an instance of the manager */
  static void Delete(AliHLTEsdManager* instance);

  /**
   * Set the options for the ESD merging and writing
   * Takes a string of blank separated options.
   * \li -writelocal   use local file writing in the specified diectory
   *                   The file name is derived from the data origin
   * \li -directory=<> Set the directory path
   *                   This makes the SetDirectory method obsolete
   * @return neg error code if failed
   */
  virtual int SetOption(const char* option)=0;

  /**
   * 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 [in]  pBuffer  the data buffer
   * @param [in]  size     data buffer size
   * @param [in]  dt       data type of the block
   * @param [out] tgtesd   optional target
   * @param [in]  eventno  optional event no
   */
  virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt,
	       AliESDEvent* tgtesd=NULL, int eventno=-1)=0;

  /**
   * Merge content of source ESD into the target ESD.
   * Merging is done on the level of objects in the ESD and for the
   * moment it's only implemented for the TClonesArrays. In that case it's
   * easy to detect whether the object is empty or not.
   *
   * \b Note: The function can not match entries of the same type, like e.g.
   * tracks from the 'Tracks' member.
   */
  virtual int Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const =0;

  /**
   * Align all ESD to the same number of events.
   * The function adds empty events to all ESD files if their event number
   * does not match the specified one.
   * @param eventno     the desired event no
   * @return neg. error code if failed
   */
  virtual int PadESDs(int eventno)=0;

  /**
   * Set the target directory for the ESD files.
   */
  virtual void SetDirectory(const char* directory)=0;

  /**
   * Get the list of the internally created files.
   * Returns a blank separated list of the file names.
   */
  virtual TString GetFileNames(AliHLTComponentDataType dt=kAliHLTAnyDataType) const = 0;

  /**
   * Create an AliESDEvent object.
   * The standard content can optionally be initialized.
   */
  virtual TObject* CreateEsdEvent(bool bCreateStdContent=false) const = 0;

  /**
   * Delete instance of AliESDEvent
   */
  virtual int DestroyEsdEvent(TObject* pESDInstance) const=0;

  /**
   * Add object to ESD event.
   * Checks the existance of the object under the name 'branchname'
   * Note: some of the objects have (branch-)names which differ from the object name
   * However, parameter branchname is never used when adding an object not yet existing.
   */
  virtual int AddObject(TObject* pESDInstance, const TObject* pObject, const char* branchname) const = 0;

  /**
   * Reset the specified object.
   * The purpose of this method is to disentangle library dependencies.
   * The actual implementation is outside the HLT base library in a
   * child class.
   */
  virtual int ResetEsdEvent(TObject* pESDInstance) const = 0;

 protected:
  /** constructor */
  AliHLTEsdManager();
  /** destructor */
  virtual ~AliHLTEsdManager();

 private:
  /** copy constructor prohibited */
  AliHLTEsdManager(const AliHLTEsdManager&);
  /** assignment operator prohibited */
  AliHLTEsdManager& operator=(const AliHLTEsdManager&);

  /** the name of the actual implementation */
  static const char* fgkImplName; //!

  /** the library of the implementation */
  static const char* fgkImplLibrary; //!

  ClassDef(AliHLTEsdManager, 0)
};

#endif
 AliHLTEsdManager.h:1
 AliHLTEsdManager.h:2
 AliHLTEsdManager.h:3
 AliHLTEsdManager.h:4
 AliHLTEsdManager.h:5
 AliHLTEsdManager.h:6
 AliHLTEsdManager.h:7
 AliHLTEsdManager.h:8
 AliHLTEsdManager.h:9
 AliHLTEsdManager.h:10
 AliHLTEsdManager.h:11
 AliHLTEsdManager.h:12
 AliHLTEsdManager.h:13
 AliHLTEsdManager.h:14
 AliHLTEsdManager.h:15
 AliHLTEsdManager.h:16
 AliHLTEsdManager.h:17
 AliHLTEsdManager.h:18
 AliHLTEsdManager.h:19
 AliHLTEsdManager.h:20
 AliHLTEsdManager.h:21
 AliHLTEsdManager.h:22
 AliHLTEsdManager.h:23
 AliHLTEsdManager.h:24
 AliHLTEsdManager.h:25
 AliHLTEsdManager.h:26
 AliHLTEsdManager.h:27
 AliHLTEsdManager.h:28
 AliHLTEsdManager.h:29
 AliHLTEsdManager.h:30
 AliHLTEsdManager.h:31
 AliHLTEsdManager.h:32
 AliHLTEsdManager.h:33
 AliHLTEsdManager.h:34
 AliHLTEsdManager.h:35
 AliHLTEsdManager.h:36
 AliHLTEsdManager.h:37
 AliHLTEsdManager.h:38
 AliHLTEsdManager.h:39
 AliHLTEsdManager.h:40
 AliHLTEsdManager.h:41
 AliHLTEsdManager.h:42
 AliHLTEsdManager.h:43
 AliHLTEsdManager.h:44
 AliHLTEsdManager.h:45
 AliHLTEsdManager.h:46
 AliHLTEsdManager.h:47
 AliHLTEsdManager.h:48
 AliHLTEsdManager.h:49
 AliHLTEsdManager.h:50
 AliHLTEsdManager.h:51
 AliHLTEsdManager.h:52
 AliHLTEsdManager.h:53
 AliHLTEsdManager.h:54
 AliHLTEsdManager.h:55
 AliHLTEsdManager.h:56
 AliHLTEsdManager.h:57
 AliHLTEsdManager.h:58
 AliHLTEsdManager.h:59
 AliHLTEsdManager.h:60
 AliHLTEsdManager.h:61
 AliHLTEsdManager.h:62
 AliHLTEsdManager.h:63
 AliHLTEsdManager.h:64
 AliHLTEsdManager.h:65
 AliHLTEsdManager.h:66
 AliHLTEsdManager.h:67
 AliHLTEsdManager.h:68
 AliHLTEsdManager.h:69
 AliHLTEsdManager.h:70
 AliHLTEsdManager.h:71
 AliHLTEsdManager.h:72
 AliHLTEsdManager.h:73
 AliHLTEsdManager.h:74
 AliHLTEsdManager.h:75
 AliHLTEsdManager.h:76
 AliHLTEsdManager.h:77
 AliHLTEsdManager.h:78
 AliHLTEsdManager.h:79
 AliHLTEsdManager.h:80
 AliHLTEsdManager.h:81
 AliHLTEsdManager.h:82
 AliHLTEsdManager.h:83
 AliHLTEsdManager.h:84
 AliHLTEsdManager.h:85
 AliHLTEsdManager.h:86
 AliHLTEsdManager.h:87
 AliHLTEsdManager.h:88
 AliHLTEsdManager.h:89
 AliHLTEsdManager.h:90
 AliHLTEsdManager.h:91
 AliHLTEsdManager.h:92
 AliHLTEsdManager.h:93
 AliHLTEsdManager.h:94
 AliHLTEsdManager.h:95
 AliHLTEsdManager.h:96
 AliHLTEsdManager.h:97
 AliHLTEsdManager.h:98
 AliHLTEsdManager.h:99
 AliHLTEsdManager.h:100
 AliHLTEsdManager.h:101
 AliHLTEsdManager.h:102
 AliHLTEsdManager.h:103
 AliHLTEsdManager.h:104
 AliHLTEsdManager.h:105
 AliHLTEsdManager.h:106
 AliHLTEsdManager.h:107
 AliHLTEsdManager.h:108
 AliHLTEsdManager.h:109
 AliHLTEsdManager.h:110
 AliHLTEsdManager.h:111
 AliHLTEsdManager.h:112
 AliHLTEsdManager.h:113
 AliHLTEsdManager.h:114
 AliHLTEsdManager.h:115
 AliHLTEsdManager.h:116
 AliHLTEsdManager.h:117
 AliHLTEsdManager.h:118
 AliHLTEsdManager.h:119
 AliHLTEsdManager.h:120
 AliHLTEsdManager.h:121
 AliHLTEsdManager.h:122
 AliHLTEsdManager.h:123
 AliHLTEsdManager.h:124
 AliHLTEsdManager.h:125
 AliHLTEsdManager.h:126
 AliHLTEsdManager.h:127
 AliHLTEsdManager.h:128
 AliHLTEsdManager.h:129
 AliHLTEsdManager.h:130
 AliHLTEsdManager.h:131
 AliHLTEsdManager.h:132
 AliHLTEsdManager.h:133
 AliHLTEsdManager.h:134
 AliHLTEsdManager.h:135
 AliHLTEsdManager.h:136
 AliHLTEsdManager.h:137
 AliHLTEsdManager.h:138
 AliHLTEsdManager.h:139
 AliHLTEsdManager.h:140
 AliHLTEsdManager.h:141
 AliHLTEsdManager.h:142
 AliHLTEsdManager.h:143
 AliHLTEsdManager.h:144
 AliHLTEsdManager.h:145
 AliHLTEsdManager.h:146
 AliHLTEsdManager.h:147
 AliHLTEsdManager.h:148
 AliHLTEsdManager.h:149
 AliHLTEsdManager.h:150
 AliHLTEsdManager.h:151
 AliHLTEsdManager.h:152
 AliHLTEsdManager.h:153
 AliHLTEsdManager.h:154
 AliHLTEsdManager.h:155
 AliHLTEsdManager.h:156
 AliHLTEsdManager.h:157
 AliHLTEsdManager.h:158
 AliHLTEsdManager.h:159
 AliHLTEsdManager.h:160
 AliHLTEsdManager.h:161