ROOT logo
//-*- Mode: C++ -*-
// @(#) $Id$

#ifndef ALIHLTMEMORYFILE_H
#define ALIHLTMEMORYFILE_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   AliHLTMemoryFile.h
    @author Matthias Richter
    @date   
    @brief  Serialization of complete ROOT files.

// see below for class documentation
// or
// refer to README to build package
// or
// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
                                                                          */
#include "TFile.h"
#include "AliHLTLogging.h"

/**
 * @class AliHLTMemoryFile
 * Serialization of ROOT files for transport in the Alice HLT analysis
 * chain.
 *
 * The file behaves like a normal ROOT file except that it is written to
 * a memory buffer instead of disk.
 */
class AliHLTMemoryFile : public TFile, public AliHLTLogging {
 public:
  /** standard constructor */
  AliHLTMemoryFile();

  /** constructor */
  AliHLTMemoryFile(void* pBuffer, int iSize);

  /** standard destructor */
  virtual ~AliHLTMemoryFile();

  /**
   * Write a header at the beginning of the file.
   * The header is not part of the ROOT file. It should be written before any
   * other object in order to avoid data to be moved.
   * @param pHeader     buffer to write
   * @param iSize       size of the buffer
   * @return neg. error code if failed
   *         - -ENOSPC    buffer size too small
   */
  int WriteHeaderBuffer(const char* pHeader, int iSize);

  /**
   * Write a header at the beginning of the file.
   * The trailer is not part of the ROOT file. It can only be written if the
   * file already has been closed.
   * @param pTrailer    buffer to write
   * @param iSize       size of the buffer
   * @return neg. error code if failed
   *         - -ENOSPC    buffer size too small
   */
  // not yet stable
  //int WriteTrailerBuffer(const char* pTrailer, int size);

  /**
   * Close file and flush output.
   * Forwards to @ref CloseMemoryFile and is introduced to avoid
   * compilation warnings about hidden virtual functions in the base class.
   */
  void Close(const Option_t*);

  /**
   * Close file and flush output.
   * @param bFlush       write remaining data
   * @return neg. error code if failed
   *         - -ENOSPC    buffer size too small
   */
  int CloseMemoryFile(int bFlush=1);

  /**
   * Check if file has been closed.
   * @return 1 if closed
   */
  int IsClosed() const {return fbClosed;}

  /**
   * Get the last error code.
   * @return error code
   */
  int GetErrno() const {return fErrno;}

  /**
   * Get header size.
   */
  int GetHeaderSize() const {return fHeaderSize;}

 protected:
  // Interface to basic system I/O routines
  Int_t    SysOpen(const char *pathname, Int_t flags, UInt_t mode);
  Int_t    SysClose(Int_t fd);
  Int_t    SysRead(Int_t fd, void *buf, Int_t len);
  Int_t    SysWrite(Int_t fd, const void *buf, Int_t len);
  Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence);
  Int_t    SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
  Int_t    SysSync(Int_t fd);

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

  /** target buffer */
  char* fpBuffer;                                                 //! transient

  /** size of buffer */
  int fBufferSize;                                                // see above

  /** position */
  int fPosition;                                                  // see above

  /** filled posrtion of the buffer */
  int fSize;                                                      // see above

  /** result of last operation */
  int fErrno;                                                     // see above

  /** file closed */
  int fbClosed;                                                   // see above

  /** size of header */
  int fHeaderSize;                                                // see above

  /** size of trailer */
  int fTrailerSize;                                               // see above

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