LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTMessage.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 10 10.0 %
Date: 2016-06-14 17:26:59 Functions: 1 17 5.9 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : /** @file   AliHLTMessage.h
       4             :     @author Matthias Richter (customization of Root TMessage )
       5             :     @date   
       6             :     @brief  Serialization of Root objects in the ALICE HLT. */
       7             : 
       8             : // This is the original Root TMessage implementation with a few minor
       9             : // modifications, original revision:
      10             : // root/net: v5-14-00 $: TMessage.h,v 1.9 2005/12/09 15:12:19 rdm
      11             : // Author: Fons Rademakers   19/12/96
      12             : //
      13             : // 2009-09-01 updating to revision
      14             : // @(#)root/net:$Id$
      15             : // Streaming problems have been encountered, especially when streaming
      16             : // TObjArrays. As long as there was just one member, the streaming was
      17             : // fine. With several members, internal variables of the objects have
      18             : // been interchanged/mixed. This bug only effected the serialization
      19             : // part, not the restoration of the object.
      20             : 
      21             : /*************************************************************************
      22             :  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
      23             :  * All rights reserved.                                                  *
      24             :  *                                                                       *
      25             :  * For the licensing terms see $ROOTSYS/LICENSE.                         *
      26             :  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
      27             :  *************************************************************************/
      28             : 
      29             : #ifndef ALIHLTMESSAGE_H
      30             : #define ALIHLTMESSAGE_H
      31             : 
      32             : 
      33             : //////////////////////////////////////////////////////////////////////////
      34             : //                                                                      //
      35             : // TMessage                                                             //
      36             : //                                                                      //
      37             : // Message buffer class used for serializing objects and sending them   //
      38             : // over the network.                                                    //
      39             : //                                                                      //
      40             : //////////////////////////////////////////////////////////////////////////
      41             : 
      42             : // TBuffer has been made pure virtual in root version v5-15-02, this
      43             : // requires to inherit from TBufferFile instead of TBuffer.
      44             : // TMessage is not really used by this class but by including it we also get
      45             : // TBufferFile if this exists. The define ROOT_TBufferFile can than be used
      46             : // to differentiate between the usage of TBuffer or TBufferFile.
      47             : #include "TMessage.h"
      48             : 
      49             : #ifndef ROOT_MessageTypes
      50             : #include "MessageTypes.h"
      51             : #endif
      52             : #ifndef ROOT_TBits
      53             : #include "TBits.h"
      54             : #endif
      55             : 
      56             : #include "AliHLTLogging.h"
      57             : /**
      58             :  * @class AliHLTMessage
      59             :  * Serialization of Root objects for transport in the Alice HLT analysis
      60             :  * chain.
      61             :  * This is the original Root TMessage implementation with a few minor
      62             :  * modifications.
      63             :  * - the <tt> AliHLTMessage(void *buf, Int_t bufsize)</tt> constructor has been
      64             :  *   made public in order to be used externally.
      65             :  *
      66             :  * The class can be used to extract an object from an input data block, or a
      67             :  * data block received via the HOMER interface or from the file writer.
      68             :  * <pre>
      69             :  *  AliHLTMessage msg(buffer, size);
      70             :  *  TObject* pObj=msg.ReadObject(msg.GetClass());
      71             :  * </pre>
      72             :  *
      73             :  * A simple test macro for a file can look like
      74             :  * <pre>
      75             :  *  const char* filename="myobject.dat";
      76             :  *  TString param=filename;
      77             :  *  param+="?filetype=raw";
      78             :  *  TFile file(param);
      79             :  *  if (file.IsZombie()) {
      80             :  *    cout << "can not open file " << filename << endl;
      81             :  *    return;
      82             :  *  }
      83             :  *  
      84             :  *  TArrayC buffer(file.GetSize());
      85             :  *  TArrayC tgtbuffer(file.GetSize());
      86             :  *  if (file.ReadBuffer(buffer.GetArray(), buffer.GetSize())) {
      87             :  *    cout << "error reading file " << filename << endl;
      88             :  *    return;
      89             :  *  }
      90             :  *
      91             :  *  AliHLTMessage msg(buffer.GetArray(), buffer.GetSize());
      92             :  *  TObject* pObj=msg.ReadObject(msg.GetClass());
      93             :  * </pre>
      94             :  *
      95             :  * @see AliHLTRootFileWriterComponent for an easy way to save objects
      96             :  * exported via AliHLTMessage in a ROOT file.
      97             :  *
      98             :  * To serialize an object into a buffer, the normal ROOT TMessage mechanism
      99             :  * can be used.
     100             :  * <pre>
     101             :  *    AliHLTMessage msg(kMESS_OBJECT);
     102             :  *    msg.WriteObject(pObject);
     103             :  *    Int_t iMsgLength=msg.Length();
     104             :  *    if (iMsgLength>0) {
     105             :  *      msg.SetLength(); // sets the length to the first (reserved) word
     106             :  *      char* pMsgBuffer msg.Buffer();
     107             :  *      // do something with pMsgBuffer and iMsgLenghth
     108             :  *    }
     109             :  * </pre>
     110             :  */
     111             : class AliHLTMessage 
     112             : :
     113             : # if defined(ROOT_TBufferFile)
     114             : public TBufferFile,
     115             : #else
     116             : public TBuffer,
     117             : #endif
     118             : public AliHLTLogging {
     119             : 
     120             : public:
     121             :    AliHLTMessage(UInt_t what = kMESS_ANY);
     122             :    AliHLTMessage(void *buf, Int_t bufsize);
     123             :    virtual ~AliHLTMessage();
     124             : 
     125             :    void SetLength() const;
     126             : 
     127             :    void     ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force);
     128             :    void     Forward();
     129           0 :    TClass  *GetClass() const { return fClass;}
     130             :    void     IncrementLevel(TVirtualStreamerInfo* info);
     131             :    void     TagStreamerInfo(TVirtualStreamerInfo *info);
     132             :    void     Reset();
     133           0 :    void     Reset(UInt_t what) { SetWhat(what); Reset(); }
     134           0 :    UInt_t   What() const { return fWhat; }
     135             :    void     SetWhat(UInt_t what);
     136             : 
     137           0 :    void     EnableSchemaEvolution(Bool_t enable = kTRUE) { fEvolution = enable; }
     138           0 :    Bool_t   UsesSchemaEvolution() const { return fEvolution; }
     139             :    void     SetCompressionLevel(Int_t level = 1);
     140           0 :    Int_t    GetCompressionLevel() const { return fCompress; }
     141             :    Int_t    Compress();
     142             :    Int_t    Uncompress();
     143           0 :    char    *CompBuffer() const { return fBufComp; }
     144           0 :    Int_t    CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
     145             :    void     WriteObject(const TObject *obj);
     146             :    UShort_t WriteProcessID(TProcessID *pid);
     147             : 
     148             :    static void   EnableSchemaEvolutionForAll(Bool_t enable = kTRUE);
     149             :    static Bool_t UsesSchemaEvolutionForAll();
     150             : 
     151           0 :    const TObjArray* GetStreamerInfos() const {return fInfos;}
     152             : 
     153             :    /**
     154             :     * Helper function to stream an object into an AliHLTMessage
     155             :     * The returned instance must be cleaned by the caller
     156             :     */
     157             :    static AliHLTMessage* Stream(TObject* pSrc, Int_t compression=1, unsigned verbosity=0,
     158             :                                 Bool_t enableSchema=kFALSE);
     159             : 
     160             :    /**
     161             :     * Helper function to extract an object from a buffer.
     162             :     * The returned object must be cleaned by the caller
     163             :     */
     164             :    static TObject* Extract(const void* pBuffer, unsigned bufferSize, unsigned verbosity=0);
     165             : 
     166             :    /**
     167             :     * Helper function to extract an object from  a file containing the streamed object.
     168             :     * The returned object must be cleaned by the caller
     169             :     */
     170             :    static TObject* Extract(const char* filename, unsigned verbosity=0);
     171             : 
     172             : private:
     173             :    UInt_t   fWhat;        //!Message type
     174             :    TClass  *fClass;       //!If message is kMESS_OBJECT pointer to object's class
     175             :    Int_t    fCompress;    //!Compression level from 0 (not compressed) to 9 (max compression)
     176             :    char    *fBufComp;     //!Compressed buffer
     177             :    char    *fBufCompCur;  //!Current position in compressed buffer
     178             :    char    *fCompPos;     //!Position of fBufCur when message was compressed
     179             :    char    *fBufUncompressed; //!Uncompressed buffer
     180             :    TBits    fBitsPIDs;    //Array of bits to mark the TProcessIDs uids written to the message
     181             :    TObjArray *fInfos;     //Array of TStreamerInfo used in WriteObject
     182             :    Bool_t   fEvolution;   //True if support for schema evolution required
     183             : 
     184             :    static Bool_t fgEvolution;  //True if global support for schema evolution required
     185             : 
     186             :    // AliHLTMessage objects cannot be copied or assigned
     187             :    AliHLTMessage(const AliHLTMessage &);           // not implemented
     188             :    void operator=(const AliHLTMessage &);     // not implemented
     189             : 
     190             :    /** the minimum size of a serialized TObject */
     191             :    static const Int_t fgkMinimumSize; //!transient
     192             : 
     193             :    /** a default buffer describing an empty message */
     194             :    static UInt_t fgkDefaultBuffer[2]; //!transient
     195             : 
     196         126 :    ClassDef(AliHLTMessage,2)  // Message buffer class
     197             : };
     198             : 
     199             : #endif // ALIHLTMESSAGE_H

Generated by: LCOV version 1.11