3 /** @file AliHLTMessage.h
4 @author Matthias Richter (customization of Root TMessage )
6 @brief Serialization of Root objects in the ALICE HLT. */
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
13 // 2009-09-01 updating to revision
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.
21 /*************************************************************************
22 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
23 * All rights reserved. *
25 * For the licensing terms see $ROOTSYS/LICENSE. *
26 * For the list of contributors see $ROOTSYS/README/CREDITS. *
27 *************************************************************************/
29 #ifndef ALIHLTMESSAGE_H
30 #define ALIHLTMESSAGE_H
33 //////////////////////////////////////////////////////////////////////////
37 // Message buffer class used for serializing objects and sending them //
38 // over the network. //
40 //////////////////////////////////////////////////////////////////////////
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.
49 #ifndef ROOT_MessageTypes
50 #include "MessageTypes.h"
56 #include "AliHLTLogging.h"
58 * @class AliHLTMessage
59 * Serialization of Root objects for transport in the Alice HLT analysis
61 * This is the original Root TMessage implementation with a few minor
63 * - the <tt> AliHLTMessage(void *buf, Int_t bufsize)</tt> constructor has been
64 * made public in order to be used externally.
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.
69 * AliHLTMessage msg(buffer, size);
70 * TObject* pObj=msg.ReadObject(msg.GetClass());
73 * A simple test macro for a file can look like
75 * const char* filename="myobject.dat";
76 * TString param=filename;
77 * param+="?filetype=raw";
79 * if (file.IsZombie()) {
80 * cout << "can not open file " << filename << endl;
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;
91 * AliHLTMessage msg(buffer.GetArray(), buffer.GetSize());
92 * TObject* pObj=msg.ReadObject(msg.GetClass());
95 * @see AliHLTRootFileWriterComponent for an easy way to save objects
96 * exported via AliHLTMessage in a ROOT file.
98 * To serialize an object into a buffer, the normal ROOT TMessage mechanism
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
113 # if defined(ROOT_TBufferFile)
118 public AliHLTLogging {
121 AliHLTMessage(UInt_t what = kMESS_ANY);
122 AliHLTMessage(void *buf, Int_t bufsize);
123 virtual ~AliHLTMessage();
125 void SetLength() const;
127 void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force);
129 TClass *GetClass() const { return fClass;}
130 void IncrementLevel(TVirtualStreamerInfo* info);
132 void Reset(UInt_t what) { SetWhat(what); Reset(); }
133 UInt_t What() const { return fWhat; }
134 void SetWhat(UInt_t what);
136 void EnableSchemaEvolution(Bool_t enable = kTRUE) { fEvolution = enable; }
137 Bool_t UsesSchemaEvolution() const { return fEvolution; }
138 void SetCompressionLevel(Int_t level = 1);
139 Int_t GetCompressionLevel() const { return fCompress; }
142 char *CompBuffer() const { return fBufComp; }
143 Int_t CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
144 void WriteObject(const TObject *obj);
145 UShort_t WriteProcessID(TProcessID *pid);
147 static void EnableSchemaEvolutionForAll(Bool_t enable = kTRUE);
148 static Bool_t UsesSchemaEvolutionForAll();
150 const TList* GetStreamerInfos() const {return fInfos;}
153 * Helper function to stream an object into an AliHLTMessage
154 * The returned instance must be cleaned by the caller
156 static AliHLTMessage* Stream(TObject* pSrc, Int_t compression=1, unsigned verbosity=0);
159 * Helper function to extract an object from a buffer.
160 * The returned object must be cleaned by the caller
162 static TObject* Extract(const void* pBuffer, unsigned bufferSize, unsigned verbosity=0);
165 * Helper function to extract an object from a file containing the streamed object.
166 * The returned object must be cleaned by the caller
168 static TObject* Extract(const char* filename, unsigned verbosity=0);
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
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
182 static Bool_t fgEvolution; //True if global support for schema evolution required
184 // AliHLTMessage objects cannot be copied or assigned
185 AliHLTMessage(const AliHLTMessage &); // not implemented
186 void operator=(const AliHLTMessage &); // not implemented
188 /** the minimum size of a serialized TObject */
189 static const Int_t fgkMinimumSize; //!transient
191 /** a default buffer describing an empty message */
192 static UInt_t fgkDefaultBuffer[2]; //!transient
194 ClassDef(AliHLTMessage,2) // Message buffer class
197 #endif // ALIHLTMESSAGE_H