]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTMessage.h
Implementation of option cw [writing of clusters]
[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 #ifndef ROOT_MessageTypes
42 #include "MessageTypes.h"
43 #endif
44
45 #include "AliHLTLogging.h"
46 /**
47  * @class AliHLTMessage
48  * Serialization of Root objects for transport in the Alice HLT analysis
49  * chain.
50  * This is the original Root TMessage implementation with a few minor
51  * modifications.
52  * - the <tt> AliHLTMessage(void *buf, Int_t bufsize)</tt> constructor has been
53  *   made public in order to be used externally.
54  *
55  * The class can be used to extract an object from an input data block, or a
56  * data block received via the HOMER interface or from the file writer.
57  * <pre>
58  *  AliHLTMessage msg(buffer, size);
59  *  TObject* pObj=msg.ReadObject(msg.GetClass());
60  * </pre>
61  *
62  * A simple test macro for a file can look like
63  * <pre>
64  *  const char* filename="myobject.dat";
65  *  TString param=filename;
66  *  param+="?filetype=raw";
67  *  TFile file(param);
68  *  if (file.IsZombie()) {
69  *    cout << "can not open file " << filename << endl;
70  *    return;
71  *  }
72  *  
73  *  TArrayC buffer(file.GetSize());
74  *  TArrayC tgtbuffer(file.GetSize());
75  *  if (file.ReadBuffer(buffer.GetArray(), buffer.GetSize())) {
76  *    cout << "error reading file " << filename << endl;
77  *    return;
78  *  }
79  *
80  *  AliHLTMessage msg(buffer.GetArray(), buffer.GetSize());
81  *  TObject* pObj=msg.ReadObject(msg.GetClass());
82  * </pre>
83  *
84  * @see AliHLTRootFileWriterComponent for an easy way to save objects
85  * exported via AliHLTMessage in a ROOT file.
86  *
87  * To serialize an object into a buffer, the normal ROOT TMessage mechanism
88  * can be used.
89  * <pre>
90  *    AliHLTMessage msg(kMESS_OBJECT);
91  *    msg.WriteObject(pObject);
92  *    Int_t iMsgLength=msg.Length();
93  *    if (iMsgLength>0) {
94  *      msg.SetLength(); // sets the length to the first (reserved) word
95  *      char* pMsgBuffer msg.Buffer();
96  *      // do something with pMsgBuffer and iMsgLenghth
97  *    }
98  * </pre>
99  */
100 class AliHLTMessage 
101 :
102 # if defined(ROOT_TBufferFile)
103 public TBufferFile,
104 #else
105 public TBuffer,
106 #endif
107 public AliHLTLogging {
108
109 public:
110    AliHLTMessage(UInt_t what = kMESS_ANY);
111    AliHLTMessage(void *buf, Int_t bufsize);
112    virtual ~AliHLTMessage();
113
114    void SetLength() const;
115
116    void     Forward();
117    TClass  *GetClass() const { return fClass; }
118    void     Reset();
119    void     Reset(UInt_t what) { SetWhat(what); Reset(); }
120    UInt_t   What() const { return fWhat; }
121    void     SetWhat(UInt_t what);
122
123    void     SetCompressionLevel(Int_t level = 1);
124    Int_t    GetCompressionLevel() const { return fCompress; }
125    Int_t    Compress();
126    Int_t    Uncompress();
127    char    *CompBuffer() const { return fBufComp; }
128    Int_t    CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
129
130 private:
131    UInt_t   fWhat;        //Message type
132    TClass  *fClass;       //If message is kMESS_OBJECT pointer to object's class
133    Int_t    fCompress;    //Compression level from 0 (not compressed) to 9 (max compression)
134    char    *fBufComp;     //Compressed buffer
135    char    *fBufCompCur;  //Current position in compressed buffer
136    char    *fCompPos;     //Position of fBufCur when message was compressed
137
138    // AliHLTMessage objects cannot be copied or assigned
139    AliHLTMessage(const AliHLTMessage &);           // not implemented
140    void operator=(const AliHLTMessage &);     // not implemented
141
142    /** the minimum size of a serialized TObject */
143    static const Int_t fgkMinimumSize; //!transient
144
145    /** a default buffer describing an empty message */
146    static UInt_t fgkDefaultBuffer[2]; //!transient
147
148    ClassDef(AliHLTMessage,0)  // Message buffer class
149 };
150
151 #endif // ALIHLTMESSAGE_H