]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTMessage.h
Minor cleanup of code.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTMessage.h
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 /*************************************************************************
14  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
15  * All rights reserved.                                                  *
16  *                                                                       *
17  * For the licensing terms see $ROOTSYS/LICENSE.                         *
18  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
19  *************************************************************************/
20
21 #ifndef ALIHLTMESSAGE_H
22 #define ALIHLTMESSAGE_H
23
24
25 //////////////////////////////////////////////////////////////////////////
26 //                                                                      //
27 // TMessage                                                             //
28 //                                                                      //
29 // Message buffer class used for serializing objects and sending them   //
30 // over the network.                                                    //
31 //                                                                      //
32 //////////////////////////////////////////////////////////////////////////
33
34 // TBuffer has been made pure virtual in root version v5-15-02, this
35 // requires to inherit from TBufferFile instead of TBuffer.
36 // TMessage is not really used by this class but by including it we also get
37 // TBufferFile if this exists. The define ROOT_TBufferFile can than be used
38 // to differentiate between the usage of TBuffer or TBufferFile.
39 #include "TMessage.h"
40
41 #if defined(HAVE_TBUFFERFILE_H)
42 #include "TBufferFile.h"
43 #endif
44
45 #ifndef ROOT_MessageTypes
46 #include "MessageTypes.h"
47 #endif
48
49 #include "AliHLTLogging.h"
50 /**
51  * @class AliHLTMessage
52  * Serialization of Root objects for transport in the Alice HLT analysis
53  * chain.
54  * This is the original Root TMessage implementation with a few minor
55  * modifications.
56  * - the <tt> AliHLTMessage(void *buf, Int_t bufsize)</tt> constructor has been
57  *   made public in order to be used externally.
58  *
59  * The class can be used to extract an object from an input data block, or a
60  * data block received via the HOMER interface or from the file writer.
61  * <pre>
62  *  AliHLTMessage msg(buffer, size);
63  *  TObject* pObj=msg.ReadObject(msg.GetClass());
64  * </pre>
65  *
66  * A simple test macro for a file can look like
67  * <pre>
68  *  const char* filename="TPC_804.ddl";
69  *  //const char* filename="TPC_768.ddl";
70  *  TString param=filename;
71  *  param+="?filetype=raw";
72  *  TFile file(param);
73  *  if (file.IsZombie()) {
74  *    cout << "can not open file " << filename << endl;
75  *    return;
76  *  }
77  *  
78  *  TArrayC buffer(file.GetSize());
79  *  TArrayC tgtbuffer(file.GetSize());
80  *  if (file.ReadBuffer(buffer.GetArray(), buffer.GetSize())) {
81  *    cout << "error reading file " << filename << endl;
82  *    return;
83  *  }
84  *
85  *  AliHLTMessage msg(buffer.GetArray(), buffer.GetSize());
86  *  TObject* pObj=msg.ReadObject(msg.GetClass());
87  * </pre>
88  *
89  * @see AliHLTRootFileWriterComponent for an easy way to save objects
90  * exported via AliHLTMessage in a ROOT file.
91  */
92 class AliHLTMessage 
93 :
94 # if defined(ROOT_TBufferFile) || defined(HAVE_TBUFFERFILE_H)
95 public TBufferFile,
96 #else
97 public TBuffer,
98 #endif
99 public AliHLTLogging {
100
101 public:
102    AliHLTMessage(UInt_t what = kMESS_ANY);
103    AliHLTMessage(void *buf, Int_t bufsize);
104    virtual ~AliHLTMessage();
105
106    void SetLength() const;
107
108    void     Forward();
109    TClass  *GetClass() const { return fClass; }
110    void     Reset();
111    void     Reset(UInt_t what) { SetWhat(what); Reset(); }
112    UInt_t   What() const { return fWhat; }
113    void     SetWhat(UInt_t what);
114
115    void     SetCompressionLevel(Int_t level = 1);
116    Int_t    GetCompressionLevel() const { return fCompress; }
117    Int_t    Compress();
118    Int_t    Uncompress();
119    char    *CompBuffer() const { return fBufComp; }
120    Int_t    CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
121
122 private:
123    UInt_t   fWhat;        //Message type
124    TClass  *fClass;       //If message is kMESS_OBJECT pointer to object's class
125    Int_t    fCompress;    //Compression level from 0 (not compressed) to 9 (max compression)
126    char    *fBufComp;     //Compressed buffer
127    char    *fBufCompCur;  //Current position in compressed buffer
128    char    *fCompPos;     //Position of fBufCur when message was compressed
129
130    // AliHLTMessage objects cannot be copied or assigned
131    AliHLTMessage(const AliHLTMessage &);           // not implemented
132    void operator=(const AliHLTMessage &);     // not implemented
133
134    ClassDef(AliHLTMessage,0)  // Message buffer class
135 };
136
137 #endif // ALIHLTMESSAGE_H