336905db1c2b6d2d90c2a262522ddbad9481e83e
[u/mrichter/AliRoot.git] / HLT / BASE / HOMER / AliHLTHOMERData.h
1 // XEMacs -*-C++-*-
2 #ifndef _HOMERDATA_HPP_
3 #define _HOMERDATA_HPP_
4
5 /************************************************************************
6 **
7 **
8 ** This file is property of and copyright by the Technical Computer
9 ** Science Group, Kirchhoff Institute for Physics, Ruprecht-Karls-
10 ** University, Heidelberg, Germany, 2001
11 ** This file has been written by Timm Morten Steinbeck, 
12 ** timm@kip.uni-heidelberg.de
13 **
14 **
15 ** See the file license.txt for details regarding usage, modification,
16 ** distribution and warranty.
17 ** Important: This file is provided without any warranty, including
18 ** fitness for any particular purpose.
19 **
20 **
21 ** Newer versions of this file's package will be made available from 
22 ** http://web.kip.uni-heidelberg.de/Hardwinf/L3/ 
23 ** or the corresponding page of the Heidelberg Alice Level 3 group.
24 **
25 *************************************************************************/
26
27 /*
28 ***************************************************************************
29 **
30 ** $Author$ - Initial Version by Timm Morten Steinbeck
31 **
32 ** $Id$ 
33 **
34 ***************************************************************************
35 */
36
37 #ifdef USE_ROOT
38 #include "Rtypes.h"
39 #endif
40 #include <limits.h>
41
42
43 // Determine the sizes of the different integer type
44 // homer_uint32, homer_uint64
45 #if !defined(USE_ROOT) && !defined(__CINT__)
46 // First homer_uint32
47 #if USHRT_MAX==4294967295
48 typedef unsigned short homer_uint32;
49 #else // USHRT_MAX==4294967295
50
51 #if UINT_MAX==4294967295
52 typedef unsigned int homer_uint32;
53 #else // UINT_MAX==4294967295
54
55 #if ULONG_MAX==4294967295l
56 typedef unsigned long homer_uint32;
57 #else // ULONG_MAX==4294967295l
58
59 #error Could not typedef homer_uint32
60
61 #endif // ULONG_MAX==4294967295l
62
63 #endif // UINT_MAX==4294967295
64
65 #endif // USHRT_MAX==4294967295
66
67 // Then homer_uint16
68 #if USHRT_MAX==65535
69 typedef unsigned short homer_uint16;
70 #else // USHRT_MAX==65535
71
72 #if UINT_MAX==65535
73 typedef unsigned int homer_uint16;
74 #else // UINT_MAX==65535
75
76 #if ULONG_MAX==65535
77 typedef unsigned long homer_uint16;
78 #else // ULONG_MAX==65535
79
80 #error Could not typedef homer_uint16
81
82 #endif // ULONG_MAX==65535
83
84 #endif // UINT_MAX==65535
85
86 #endif // USHRT_MAX==65535
87
88 // Then homer_uint64
89 #if ULONG_MAX==18446744073709551615ULL
90 typedef unsigned long homer_uint64;
91 #else // ULONG_MAX==18446744073709551615UL
92
93 #if defined __GNUC__
94 typedef unsigned long long homer_uint64;
95 #else // defined __GNUC__
96
97 #error Could not typedef homer_uint64
98
99 #endif // defined __GNUC__
100
101 #endif // ULONG_MAX==18446744073709551615UL
102
103 typedef unsigned char homer_uint8;
104
105 #else // !USE_ROOT && !CINT
106
107
108 typedef UShort_t homer_uint16;
109 typedef UInt_t homer_uint32;
110 typedef ULong64_t homer_uint64;
111 typedef Byte_t homer_uint8;
112
113 #ifdef __CINT__
114 typedef int key_t;
115 #endif
116
117 #endif // USE_ROOT
118
119 //typedef homer_uint64 AliEventID_t;
120
121
122
123 const unsigned kAttribute_8b_StartOffset = 0;
124 const unsigned kByteOrderAttribute_8b_Offset = kAttribute_8b_StartOffset+0;
125 const unsigned kVersionAttribute_8b_Offset = kAttribute_8b_StartOffset+1;
126 const unsigned kAlignment_8b_StartOffset = 24;
127 const unsigned kUInt64Alignment_8b_Offset = kAlignment_8b_StartOffset+0;
128 const unsigned kUInt32Alignment_8b_Offset = kAlignment_8b_StartOffset+1;
129 const unsigned kUInt16Alignment_8b_Offset = kAlignment_8b_StartOffset+2;
130 const unsigned kUInt8Alignment_8b_Offset = kAlignment_8b_StartOffset+3;
131 const unsigned kDoubleAlignment_8b_Offset = kAlignment_8b_StartOffset+4;
132 const unsigned kFloatAlignment_8b_Offset = kAlignment_8b_StartOffset+5;
133
134
135 const unsigned kID_64b_Offset = 1;
136 const unsigned kLength_64b_Offset = 2;
137 const unsigned kType_64b_Offset = 4;
138 const unsigned kSubType1_64b_Offset = 5;
139 const unsigned kSubType2_64b_Offset = 6;
140 const unsigned kBirth_s_64b_Offset = 7;
141 const unsigned kBirth_us_64b_Offset = 8;
142 const unsigned kProducerNode_64b_Offset = 9;
143 const unsigned kOffset_64b_Offset = 10;
144 const unsigned kSize_64b_Offset = 11;
145 const unsigned kStatusFlags_64b_Offset = 12;
146 const unsigned kEnd_64b_Offset = 13;
147 const unsigned kCount_64b_Words = kEnd_64b_Offset;
148
149
150 // Possible values for fAttributes[kByteOrderAttribute]
151 /* Keep this consistent with BCLNetworkData.hpp kLittleEndian/kBigEndian and AliHLTSubEventDataDescriptor.hpp */
152 const homer_uint8 kHOMERUnknownByteOrder      = 0;
153 const homer_uint8 kHOMERLittleEndianByteOrder = 1;
154 const homer_uint8 kHOMERBigEndianByteOrder    = 2;
155 #ifdef __i386__
156     const homer_uint8 kHOMERNativeByteOrder = kHOMERLittleEndianByteOrder;
157 #else
158 #ifdef __arm__
159     const homer_uint8 kHOMERNativeByteOrder = kHOMERLittleEndianByteOrder;
160 #else
161 #ifdef __x86_64__
162     const homer_uint8 kHOMERNativeByteOrder = kHOMERLittleEndianByteOrder;
163 #else
164 #ifdef __ia64__
165     const homer_uint8 kHOMERNativeByteOrder = kHOMERLittleEndianByteOrder;
166 #else
167 #if defined(__powerpc__)
168     const homer_uint8 kHOMERNativeByteOrder = kHOMERBigEndianByteOrder;
169 #else
170 #ifdef __CINT__
171     const homer_uint8 kHOMERNativeByteOrder = kHOMERLittleEndianByteOrder;
172 #warning Assuming little endian format for __CINT__
173 #else
174 #error Byte format (little/big endian) currently not defined for platforms other than intel i386 compatible, x86-64 (AMD64) and arm...
175 #endif
176 #endif
177 #endif
178 #endif
179 #endif
180 #endif
181
182
183 //#define HOMER_BLOCK_DESCRIPTOR_TYPEID             (((homer_uint64)'HOBL')<<32 | 'KDES')
184 #define HOMER_BLOCK_DESCRIPTOR_TYPEID               ( (((homer_uint64)'H')<<56)|(((homer_uint64)'O')<<48)|(((homer_uint64)'B')<<40)|(((homer_uint64)'L')<<32)|(((homer_uint64)'K')<<24)|(((homer_uint64)'D')<<16)|(((homer_uint64)'E')<<8)|(((homer_uint64)'S')<<0) )
185 //#define HOMER_BLOCK_DESCRIPTOR_TYPEID            ( (((homer_uint64)'H')<<56)|(((homer_uint64)'O')<<48) )
186 #define HOMER_HEADER_CURRENT_VERSION              2
187
188
189 class HOMERBlockDescriptor
190     {
191     public:
192
193         static unsigned GetHOMERBlockDescriptorSize()
194                 {
195                 return sizeof(homer_uint64)*kCount_64b_Words;
196                 }
197
198         HOMERBlockDescriptor( void* header = 0 )
199                 {
200                 fHeader = header;
201                 }
202         void UseHeader( void* header )
203                 {
204                 fHeader = header;
205                 }
206         void Initialize()
207                 {
208                 if ( fHeader )
209                     {
210                     for ( unsigned ii=0; ii<kCount_64b_Words; ii++ )
211                         ((homer_uint64*)fHeader)[ ii ] = (homer_uint64)0;
212                     ((homer_uint64*)fHeader)[ kID_64b_Offset ] = HOMER_BLOCK_DESCRIPTOR_TYPEID;
213                     ((homer_uint64*)fHeader)[ kLength_64b_Offset ] = GetHOMERBlockDescriptorSize();
214                     ((homer_uint8*)fHeader)[ kByteOrderAttribute_8b_Offset ] = kHOMERNativeByteOrder;
215                     ((homer_uint8*)fHeader)[ kVersionAttribute_8b_Offset ] = HOMER_HEADER_CURRENT_VERSION;
216                     }
217                 }
218
219         void SetByteOrder( homer_uint8 bo )
220                 {
221                 if ( fHeader )
222                     ((homer_uint8*)fHeader)[ kByteOrderAttribute_8b_Offset ] = bo;
223                 }
224         homer_uint8 GetByteOrder() const 
225                 {
226                 if ( fHeader )
227                     return ((homer_uint8*)fHeader)[ kByteOrderAttribute_8b_Offset ];
228                 else
229                     return 0xFF;
230                 }
231         void SetVersion( homer_uint8 v )
232                 {
233                 if ( fHeader )
234                     ((homer_uint8*)fHeader)[ kVersionAttribute_8b_Offset ] = v;
235                 }
236         void SetID( homer_uint64 id  )
237                 {
238                 if ( fHeader )
239                     ((homer_uint64*)fHeader)[ kID_64b_Offset ] = id;
240                 }
241         void SetHeaderLength( homer_uint64 l  )
242                 {
243                 if ( fHeader )
244                     ((homer_uint64*)fHeader)[ kLength_64b_Offset ] = l;
245                 }
246         homer_uint64 GetHeaderLength()
247                 {
248                 if ( fHeader )
249                     return ((homer_uint64*)fHeader)[ kLength_64b_Offset ];
250                 else
251                     return 0;
252                 }
253         void SetAlignment( homer_uint8 type, homer_uint8 align )
254                 {
255                 if ( fHeader && type<6 )
256                     ((homer_uint8*)fHeader)[ kAlignment_8b_StartOffset+type ] = align;
257                 }
258         void SetUInt64Alignment( homer_uint8 align )
259                 {
260                 if ( fHeader )
261                     ((homer_uint8*)fHeader)[ kUInt64Alignment_8b_Offset ] = align;
262                 }
263         void SetUInt32Alignment( homer_uint8 align )
264                 {
265                 if ( fHeader )
266                     ((homer_uint8*)fHeader)[ kUInt32Alignment_8b_Offset ] = align;
267                 }
268         void SetUInt16Alignment( homer_uint8 align )
269                 {
270                 if ( fHeader )
271                     ((homer_uint8*)fHeader)[ kUInt16Alignment_8b_Offset ] = align;
272                 }
273         void SetUInt8Alignment( homer_uint8 align )
274                 {
275                 if ( fHeader )
276                     ((homer_uint8*)fHeader)[ kUInt8Alignment_8b_Offset ] = align;
277                 }
278         void SetDoubleAlignment( homer_uint8 align )
279                 {
280                 if ( fHeader )
281                     ((homer_uint8*)fHeader)[ kDoubleAlignment_8b_Offset ] = align;
282                 }
283         void SetFloatAlignment( homer_uint8 align )
284                 {
285                 if ( fHeader )
286                     ((homer_uint8*)fHeader)[ kFloatAlignment_8b_Offset ] = align;
287                 }
288         void SetType( homer_uint64 t )
289                 {
290                 if ( fHeader )
291                     ((homer_uint64*)fHeader)[ kType_64b_Offset ] = t;
292                 }
293         void SetSubType1( homer_uint64 st1 )
294                 {
295                 if ( fHeader )
296                     ((homer_uint64*)fHeader)[ kSubType1_64b_Offset ] = st1;
297                 }
298         void SetSubType2( homer_uint64 st2 )
299                 {
300                 if ( fHeader )
301                     ((homer_uint64*)fHeader)[ kSubType2_64b_Offset ] = st2;
302                 }
303         void SetBirth_s( homer_uint64 bs )
304                 {
305                 if ( fHeader )
306                     ((homer_uint64*)fHeader)[ kBirth_s_64b_Offset ] = bs;
307                 }
308         void SetBirth_us( homer_uint64 bus )
309                 {
310                 if ( fHeader )
311                     ((homer_uint64*)fHeader)[ kBirth_us_64b_Offset ] = bus;
312                 }
313         void SetProducerNode( homer_uint64 pn )
314                 {
315                 if ( fHeader )
316                     ((homer_uint64*)fHeader)[ kProducerNode_64b_Offset ] = pn;
317                 }
318         void SetBlockOffset( homer_uint64 bo )
319                 {
320                 if ( fHeader )
321                     ((homer_uint64*)fHeader)[ kOffset_64b_Offset ] = bo;
322                 }
323         homer_uint64 GetBlockOffset()
324                 {
325                 if ( fHeader )
326                     return ((homer_uint64*)fHeader)[ kOffset_64b_Offset ];
327                 else
328                     return 0;
329                 }
330         void SetBlockSize( homer_uint64 bs )
331                 {
332                 if ( fHeader )
333                     ((homer_uint64*)fHeader)[ kSize_64b_Offset ] = bs;
334                 }
335         homer_uint64 GetBlockSize()
336                 {
337                 if ( fHeader )
338                     return ((homer_uint64*)fHeader)[ kSize_64b_Offset ];
339                 else
340                     return 0;
341                 }
342         void SetStatusFlags( homer_uint64 bs )
343                 {
344                 if ( fHeader )
345                     ((homer_uint64*)fHeader)[ kStatusFlags_64b_Offset ] = bs;
346                 }
347         homer_uint64 GetStatusFlags()
348                 {
349                 if ( fHeader )
350                     return ((homer_uint64*)fHeader)[ kStatusFlags_64b_Offset ];
351                 else
352                     return 0;
353                 }
354
355         void* GetHeader() const
356                 {
357                 return fHeader;
358                 }
359                 
360     protected:
361         void* fHeader;
362         
363
364     };
365
366
367
368 /*
369 ***************************************************************************
370 **
371 ** $Author$ - Initial Version by Timm Morten Steinbeck
372 **
373 ** $Id$ 
374 **
375 ***************************************************************************
376 */
377
378 #endif // _HOMERDATA_HPP_