]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTMessage.h
Fixing generation of bit mask for TObject::fBits field.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTMessage.h
CommitLineData
a655eae3 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
257aedf5 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.
a655eae3 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// //
dfaa582a 35// TMessage //
a655eae3 36// //
37// Message buffer class used for serializing objects and sending them //
38// over the network. //
39// //
40//////////////////////////////////////////////////////////////////////////
41
dfaa582a 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
a655eae3 49#ifndef ROOT_MessageTypes
50#include "MessageTypes.h"
51#endif
257aedf5 52#ifndef ROOT_TBits
53#include "TBits.h"
54#endif
a655eae3 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.
aa7f26de 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);
d6b69874 70 * TObject* pObj=msg.ReadObject(msg.GetClass());
aa7f26de 71 * </pre>
d6b69874 72 *
73 * A simple test macro for a file can look like
74 * <pre>
5cdaceed 75 * const char* filename="myobject.dat";
d6b69874 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.
5cdaceed 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>
a655eae3 110 */
dfaa582a 111class AliHLTMessage
112:
ba4b0dd7 113# if defined(ROOT_TBufferFile)
dfaa582a 114public TBufferFile,
115#else
116public TBuffer,
117#endif
118public AliHLTLogging {
a655eae3 119
120public:
121 AliHLTMessage(UInt_t what = kMESS_ANY);
122 AliHLTMessage(void *buf, Int_t bufsize);
123 virtual ~AliHLTMessage();
124
125 void SetLength() const;
126
257aedf5 127 void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force);
a655eae3 128 void Forward();
257aedf5 129 TClass *GetClass() const { return fClass;}
130 void IncrementLevel(TVirtualStreamerInfo* info);
a655eae3 131 void Reset();
132 void Reset(UInt_t what) { SetWhat(what); Reset(); }
133 UInt_t What() const { return fWhat; }
134 void SetWhat(UInt_t what);
135
257aedf5 136 void EnableSchemaEvolution(Bool_t enable = kTRUE) { fEvolution = enable; }
137 Bool_t UsesSchemaEvolution() const { return fEvolution; }
a655eae3 138 void SetCompressionLevel(Int_t level = 1);
139 Int_t GetCompressionLevel() const { return fCompress; }
140 Int_t Compress();
141 Int_t Uncompress();
142 char *CompBuffer() const { return fBufComp; }
143 Int_t CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
257aedf5 144 void WriteObject(const TObject *obj);
145 UShort_t WriteProcessID(TProcessID *pid);
146
147 static void EnableSchemaEvolutionForAll(Bool_t enable = kTRUE);
148 static Bool_t UsesSchemaEvolutionForAll();
a655eae3 149
e0617052 150 const TList* GetStreamerInfos() const {return fInfos;}
151
e5701dcf 152 /**
153 * Helper function to stream an object into an AliHLTMessage
154 * The returned instance must be cleaned by the caller
155 */
156 static AliHLTMessage* Stream(TObject* pSrc, Int_t compression=1, unsigned verbosity=0);
157
158 /**
159 * Helper function to extract an object from a buffer.
160 * The returned object must be cleaned by the caller
161 */
162 static TObject* Extract(const void* pBuffer, unsigned bufferSize, unsigned verbosity=0);
163
f5e1aed1 164 /**
165 * Helper function to extract an object from a file containing the streamed object.
166 * The returned object must be cleaned by the caller
167 */
168 static TObject* Extract(const char* filename, unsigned verbosity=0);
169
a655eae3 170private:
0634add1 171 UInt_t fWhat; //!Message type
172 TClass *fClass; //!If message is kMESS_OBJECT pointer to object's class
173 Int_t fCompress; //!Compression level from 0 (not compressed) to 9 (max compression)
174 char *fBufComp; //!Compressed buffer
175 char *fBufCompCur; //!Current position in compressed buffer
176 char *fCompPos; //!Position of fBufCur when message was compressed
177 char *fBufUncompressed; //!Uncompressed buffer
257aedf5 178 TBits fBitsPIDs; //Array of bits to mark the TProcessIDs uids written to the message
179 TList *fInfos; //Array of TStreamerInfo used in WriteObject
180 Bool_t fEvolution; //True if support for schema evolution required
181
182 static Bool_t fgEvolution; //True if global support for schema evolution required
a655eae3 183
184 // AliHLTMessage objects cannot be copied or assigned
185 AliHLTMessage(const AliHLTMessage &); // not implemented
186 void operator=(const AliHLTMessage &); // not implemented
187
5cdaceed 188 /** the minimum size of a serialized TObject */
189 static const Int_t fgkMinimumSize; //!transient
190
191 /** a default buffer describing an empty message */
192 static UInt_t fgkDefaultBuffer[2]; //!transient
193
257aedf5 194 ClassDef(AliHLTMessage,2) // Message buffer class
a655eae3 195};
196
197#endif // ALIHLTMESSAGE_H