]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/HOMER/AliHLTHOMERWriter.cxx
ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / BASE / HOMER / AliHLTHOMERWriter.cxx
1 /************************************************************************
2 **
3 **
4 ** This file is property of and copyright by the Technical Computer
5 ** Science Group, Kirchhoff Institute for Physics, Ruprecht-Karls-
6 ** University, Heidelberg, Germany, 2001
7 ** This file has been written by Timm Morten Steinbeck, 
8 ** timm@kip.uni-heidelberg.de
9 **
10 **
11 ** See the file license.txt for details regarding usage, modification,
12 ** distribution and warranty.
13 ** Important: This file is provided without any warranty, including
14 ** fitness for any particular purpose.
15 **
16 **
17 ** Newer versions of this file's package will be made available from 
18 ** http://web.kip.uni-heidelberg.de/Hardwinf/L3/ 
19 ** or the corresponding page of the Heidelberg Alice Level 3 group.
20 **
21 *************************************************************************/
22
23 /*
24 ***************************************************************************
25 **
26 ** $Author$ - Initial Version by Timm Morten Steinbeck
27 **
28 ** $Id$ 
29 **
30 ***************************************************************************
31 */
32
33 /** @file   AliHLTHOMERWriter.cxx
34     @author Timm Steinbeck
35     @date   Sep 14 2007
36     @brief  HLT Online Monitoring Environment including ROOT - Writer   
37     @note   migrated from PubSub HLT-stable-20070905.141318 (rev 2375)    */
38
39 // see header file for class documentation
40 // or
41 // refer to README to build package
42 // or
43 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
44
45 #include <cstring>
46 #include "AliHLTHOMERWriter.h"
47 #include <sys/time.h>
48 #include <time.h>
49
50
51 AliHLTHOMERWriter::AliHLTHOMERWriter()
52   :
53   fDataOffset(0),
54   fBlocks()
55     {
56     // Writer implementation of the HOMER interface.
57     // The HLT Monitoring Environment including ROOT is
58     // a native interface to ship out data from the HLT chain.
59     // See pdf document shiped with the package
60     // for class documentation and tutorial.
61     Clear();
62     }
63
64 AliHLTHOMERWriter::~AliHLTHOMERWriter()
65     {
66     // see header file for class documentation
67     }
68
69 void AliHLTHOMERWriter::Clear()
70     {
71     // see header file for class documentation
72     fDataOffset = 0;
73     fBlocks.clear();
74     }
75
76 void AliHLTHOMERWriter::AddBlock( const void* descriptor, const void* data )
77     {
78     // see header file for class documentation
79     TBlockData bd;
80     memcpy( bd.fDescriptor, descriptor, HOMERBlockDescriptor::GetHOMERBlockDescriptorSize() );
81     bd.fData = data;
82     HOMERBlockDescriptor hbd( &bd.fDescriptor );
83     hbd.SetBlockOffset( fDataOffset );
84     fDataOffset += hbd.GetBlockSize();
85     fBlocks.push_back( bd );
86     }
87
88 homer_uint32 AliHLTHOMERWriter::GetTotalMemorySize( bool includeData )
89     {
90     // see header file for class documentation
91     if ( includeData )
92         return fDataOffset + HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
93     else
94         return HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
95     }
96
97 void AliHLTHOMERWriter::Copy( void* destination, homer_uint64 eventType, homer_uint64 eventNr, homer_uint64 statusFlags, homer_uint64 nodeID, bool includeData )
98     {
99     // see header file for class documentation
100     HOMERBlockDescriptor homerBlock;
101     homer_uint8* bd = reinterpret_cast<homer_uint8*>( destination );
102     struct timeval now;
103     gettimeofday( &now, NULL );
104     homerBlock.UseHeader( bd );
105     homerBlock.Initialize();
106     homerBlock.SetUInt64Alignment( AliHLTHOMERWriter::DetermineUInt64Alignment() );
107     homerBlock.SetUInt32Alignment( AliHLTHOMERWriter::DetermineUInt32Alignment() );
108     homerBlock.SetUInt16Alignment( AliHLTHOMERWriter::DetermineUInt16Alignment() );
109     homerBlock.SetUInt8Alignment( AliHLTHOMERWriter::DetermineUInt8Alignment() );
110     homerBlock.SetDoubleAlignment( AliHLTHOMERWriter::DetermineDoubleAlignment() );
111     homerBlock.SetFloatAlignment( AliHLTHOMERWriter::DetermineFloatAlignment() );
112     homerBlock.SetType( eventType );
113     homerBlock.SetSubType1( eventNr );
114     homerBlock.SetSubType2( fBlocks.size() );
115     homerBlock.SetBirth_s( now.tv_sec );
116     homerBlock.SetBirth_us( now.tv_usec );
117     homerBlock.SetProducerNode( nodeID );
118     homerBlock.SetBlockOffset( homerBlock.GetHeaderLength() );
119     homerBlock.SetBlockSize( HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*fBlocks.size() );
120     homerBlock.SetStatusFlags( statusFlags );
121     bd += homerBlock.GetHeaderLength();
122
123     //unsigned long dataOffset = HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
124     unsigned long dataOffset = homerBlock.GetBlockOffset() + homerBlock.GetBlockSize();
125     std::vector<TBlockData>::iterator iter, end;
126     iter = fBlocks.begin();
127     end = fBlocks.end();
128     while ( iter != end )
129         {
130         homerBlock.UseHeader( iter->fDescriptor );
131         homerBlock.SetBlockOffset( homerBlock.GetBlockOffset()+dataOffset );
132         memcpy( bd, iter->fDescriptor, homerBlock.GetHeaderLength() );
133         bd += homerBlock.GetHeaderLength();
134         if ( includeData )
135             {
136             memcpy( ((homer_uint8*)destination)+homerBlock.GetBlockOffset(), iter->fData, homerBlock.GetBlockSize() );
137             }
138         iter++;
139         }
140     }
141
142 homer_uint8 AliHLTHOMERWriter::DetermineUInt64Alignment()
143     {
144     // see header file for class documentation
145     AliHLTHOMERWriterAlignment64TestStructure test;
146     if ( (unsigned long)(&test.f64Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
147         {
148         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
149         return ~(homer_uint8)0;
150         }
151     if ( (unsigned long)(&test.f64Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
152         {
153         // The 64 bit element does not immediately follow the 32 bit element, 
154         // therefore the alignment has to be greater than 4.
155         return (homer_uint8)8;
156         }
157     if ( (unsigned long)(&test.f64Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
158         {
159         // The 64 bit element does not immediately follow the 16 bit element, 
160         // therefore the alignment has to be greater than 2.
161         return (homer_uint8)4;
162         }
163     if ( (unsigned long)(&test.f64Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
164         {
165         // The 64 bit element does not immediately follow the 8 bit element, 
166         // therefore the alignment has to be greater than 1.
167         return (homer_uint8)2;
168         }
169     return 1;
170     }
171
172 homer_uint8 AliHLTHOMERWriter::DetermineUInt32Alignment()
173     {
174     // see header file for class documentation
175     AliHLTHOMERWriterAlignment32TestStructure test;
176     if ( (unsigned long)(&test.f32Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
177         {
178         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
179         return ~(homer_uint8)0;
180         }
181     if ( (unsigned long)(&test.f32Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
182         {
183         // The 32 bit element does not immediately follow the 32 bit element, 
184         // therefore the alignment has to be greater than 4.
185         return (homer_uint8)8;
186         }
187     if ( (unsigned long)(&test.f32Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
188         {
189         // The 32 bit element does not immediately follow the 16 bit element, 
190         // therefore the alignment has to be greater than 2.
191         return (homer_uint8)4;
192         }
193     if ( (unsigned long)(&test.f32Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
194         {
195         // The 32 bit element does not immediately follow the 8 bit element, 
196         // therefore the alignment has to be greater than 1.
197         return (homer_uint8)2;
198         }
199     return 1;
200     }
201
202 homer_uint8 AliHLTHOMERWriter::DetermineUInt16Alignment()
203     {
204     // see header file for class documentation
205     AliHLTHOMERWriterAlignment16TestStructure test;
206     if ( (unsigned long)(&test.f16Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
207         {
208         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
209         return ~(homer_uint8)0;
210         }
211     if ( (unsigned long)(&test.f16Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
212         {
213         // The 16 bit element does not immediately follow the 32 bit element, 
214         // therefore the alignment has to be greater than 4.
215         return (homer_uint8)8;
216         }
217     if ( (unsigned long)(&test.f16Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
218         {
219         // The 16 bit element does not immediately follow the 16 bit element, 
220         // therefore the alignment has to be greater than 2.
221         return (homer_uint8)4;
222         }
223     if ( (unsigned long)(&test.f16Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
224         {
225         // The 16 bit element does not immediately follow the 8 bit element, 
226         // therefore the alignment has to be greater than 1.
227         return (homer_uint8)2;
228         }
229     return 1;
230     }
231
232 homer_uint8 AliHLTHOMERWriter::DetermineUInt8Alignment()
233     {
234     // see header file for class documentation
235     AliHLTHOMERWriterAlignment8TestStructure test;
236     if ( (unsigned long)(&test.f8Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
237         {
238         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
239         return ~(homer_uint8)0;
240         }
241     if ( (unsigned long)(&test.f8Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
242         {
243         // The 8 bit element does not immediately follow the 32 bit element, 
244         // therefore the alignment has to be greater than 4.
245         return (homer_uint8)8;
246         }
247     if ( (unsigned long)(&test.f8Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
248         {
249         // The 8 bit element does not immediately follow the 16 bit element, 
250         // therefore the alignment has to be greater than 2.
251         return (homer_uint8)4;
252         }
253     if ( (unsigned long)(&test.f8Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
254         {
255         // The 8 bit element does not immediately follow the 8 bit element, 
256         // therefore the alignment has to be greater than 1.
257         return (homer_uint8)2;
258         }
259     return 1;
260     }
261
262 homer_uint8 AliHLTHOMERWriter::DetermineDoubleAlignment()
263     {
264     // see header file for class documentation
265     AliHLTHOMERWriterAlignmentDoubleTestStructure test;
266     if ( (unsigned long)(&test.fDoubleTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
267         {
268         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
269         return ~(homer_uint8)0;
270         }
271     if ( (unsigned long)(&test.fDoubleTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
272         {
273         // The double element does not immediately follow the 32 bit element, 
274         // therefore the alignment has to be greater than 4.
275         return (homer_uint8)8;
276         }
277     if ( (unsigned long)(&test.fDoubleTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
278         {
279         // The double element does not immediately follow the 16 bit element, 
280         // therefore the alignment has to be greater than 2.
281         return (homer_uint8)4;
282         }
283     if ( (unsigned long)(&test.fDoubleTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
284         {
285         // The double element does not immediately follow the 8 bit element, 
286         // therefore the alignment has to be greater than 1.
287         return (homer_uint8)2;
288         }
289     return 1;
290     }
291
292 homer_uint8 AliHLTHOMERWriter::DetermineFloatAlignment()
293     {
294     // see header file for class documentation
295     AliHLTHOMERWriterAlignmentFloatTestStructure test;
296     if ( (unsigned long)(&test.fFloatTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
297         {
298         // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
299         return ~(homer_uint8)0;
300         }
301     if ( (unsigned long)(&test.fFloatTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
302         {
303         // The float element does not immediately follow the 32 bit element, 
304         // therefore the alignment has to be greater than 4.
305         return (homer_uint8)8;
306         }
307     if ( (unsigned long)(&test.fFloatTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
308         {
309         // The float element does not immediately follow the 16 bit element, 
310         // therefore the alignment has to be greater than 2.
311         return (homer_uint8)4;
312         }
313     if ( (unsigned long)(&test.fFloatTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
314         {
315         // The float element does not immediately follow the 8 bit element, 
316         // therefore the alignment has to be greater than 1.
317         return (homer_uint8)2;
318         }
319     return 1;
320     }
321
322 AliHLTHOMERWriter* AliHLTHOMERWriterCreate()
323     {
324     // see header file for function documentation
325     return new AliHLTHOMERWriter();
326     }
327
328 void AliHLTHOMERWriterDelete(AliHLTHOMERWriter* pInstance)
329     {
330     // see header file for function documentation
331     if (pInstance) delete pInstance;
332     }
333
334
335 /*
336 ***************************************************************************
337 **
338 ** $Author$ - Initial Version by Timm Morten Steinbeck
339 **
340 ** $Id$ 
341 **
342 ***************************************************************************
343 */