Line data Source code
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 0 : AliHLTHOMERWriter::AliHLTHOMERWriter()
52 : :
53 0 : fDataOffset(0),
54 0 : fBlocks()
55 0 : {
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 0 : Clear();
62 0 : }
63 :
64 : AliHLTHOMERWriter::~AliHLTHOMERWriter()
65 0 : {
66 : // see header file for class documentation
67 0 : }
68 :
69 : void AliHLTHOMERWriter::Clear()
70 : {
71 : // see header file for class documentation
72 0 : fDataOffset = 0;
73 0 : fBlocks.clear();
74 0 : }
75 :
76 : void AliHLTHOMERWriter::AddBlock( const void* descriptor, const void* data )
77 : {
78 : // see header file for class documentation
79 0 : TBlockData bd;
80 0 : memcpy( bd.fDescriptor, descriptor, HOMERBlockDescriptor::GetHOMERBlockDescriptorSize() );
81 0 : bd.fData = data;
82 0 : HOMERBlockDescriptor hbd( &bd.fDescriptor );
83 0 : hbd.SetBlockOffset( fDataOffset );
84 0 : fDataOffset += hbd.GetBlockSize();
85 0 : fBlocks.push_back( bd );
86 0 : }
87 :
88 : homer_uint32 AliHLTHOMERWriter::GetTotalMemorySize( bool includeData )
89 : {
90 : // see header file for class documentation
91 0 : if ( includeData )
92 0 : return fDataOffset + HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
93 : else
94 0 : return HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
95 0 : }
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 0 : HOMERBlockDescriptor homerBlock;
101 : homer_uint8* bd = reinterpret_cast<homer_uint8*>( destination );
102 0 : struct timeval now;
103 0 : gettimeofday( &now, NULL );
104 0 : homerBlock.UseHeader( bd );
105 0 : homerBlock.Initialize();
106 0 : homerBlock.SetUInt64Alignment( AliHLTHOMERWriter::DetermineUInt64Alignment() );
107 0 : homerBlock.SetUInt32Alignment( AliHLTHOMERWriter::DetermineUInt32Alignment() );
108 0 : homerBlock.SetUInt16Alignment( AliHLTHOMERWriter::DetermineUInt16Alignment() );
109 0 : homerBlock.SetUInt8Alignment( AliHLTHOMERWriter::DetermineUInt8Alignment() );
110 0 : homerBlock.SetDoubleAlignment( AliHLTHOMERWriter::DetermineDoubleAlignment() );
111 0 : homerBlock.SetFloatAlignment( AliHLTHOMERWriter::DetermineFloatAlignment() );
112 0 : homerBlock.SetType( eventType );
113 0 : homerBlock.SetSubType1( eventNr );
114 0 : homerBlock.SetSubType2( fBlocks.size() );
115 0 : homerBlock.SetBirth_s( now.tv_sec );
116 0 : homerBlock.SetBirth_us( now.tv_usec );
117 0 : homerBlock.SetProducerNode( nodeID );
118 0 : homerBlock.SetBlockOffset( homerBlock.GetHeaderLength() );
119 0 : homerBlock.SetBlockSize( HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*fBlocks.size() );
120 0 : homerBlock.SetStatusFlags( statusFlags );
121 0 : bd += homerBlock.GetHeaderLength();
122 :
123 : //unsigned long dataOffset = HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
124 0 : unsigned long dataOffset = homerBlock.GetBlockOffset() + homerBlock.GetBlockSize();
125 0 : std::vector<TBlockData>::iterator iter, end;
126 0 : iter = fBlocks.begin();
127 0 : end = fBlocks.end();
128 0 : while ( iter != end )
129 : {
130 0 : homerBlock.UseHeader( iter->fDescriptor );
131 0 : homerBlock.SetBlockOffset( homerBlock.GetBlockOffset()+dataOffset );
132 0 : memcpy( bd, iter->fDescriptor, homerBlock.GetHeaderLength() );
133 0 : bd += homerBlock.GetHeaderLength();
134 0 : if ( includeData )
135 : {
136 0 : memcpy( ((homer_uint8*)destination)+homerBlock.GetBlockOffset(), iter->fData, homerBlock.GetBlockSize() );
137 0 : }
138 0 : iter++;
139 : }
140 0 : }
141 :
142 : homer_uint8 AliHLTHOMERWriter::DetermineUInt64Alignment()
143 : {
144 : // see header file for class documentation
145 0 : AliHLTHOMERWriterAlignment64TestStructure test;
146 0 : 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 0 : return ~(homer_uint8)0;
150 : }
151 0 : 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 0 : return (homer_uint8)8;
156 : }
157 0 : 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 0 : return (homer_uint8)4;
162 : }
163 0 : 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 0 : return (homer_uint8)2;
168 : }
169 0 : return 1;
170 0 : }
171 :
172 : homer_uint8 AliHLTHOMERWriter::DetermineUInt32Alignment()
173 : {
174 : // see header file for class documentation
175 0 : AliHLTHOMERWriterAlignment32TestStructure test;
176 0 : 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 0 : return ~(homer_uint8)0;
180 : }
181 0 : 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 0 : return (homer_uint8)8;
186 : }
187 0 : 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 0 : return (homer_uint8)4;
192 : }
193 0 : 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 0 : return (homer_uint8)2;
198 : }
199 0 : return 1;
200 0 : }
201 :
202 : homer_uint8 AliHLTHOMERWriter::DetermineUInt16Alignment()
203 : {
204 : // see header file for class documentation
205 0 : AliHLTHOMERWriterAlignment16TestStructure test;
206 0 : 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 0 : return ~(homer_uint8)0;
210 : }
211 0 : 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 0 : return (homer_uint8)8;
216 : }
217 0 : 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 0 : return (homer_uint8)4;
222 : }
223 0 : 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 0 : return (homer_uint8)2;
228 : }
229 0 : return 1;
230 0 : }
231 :
232 : homer_uint8 AliHLTHOMERWriter::DetermineUInt8Alignment()
233 : {
234 : // see header file for class documentation
235 0 : AliHLTHOMERWriterAlignment8TestStructure test;
236 0 : 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 0 : return ~(homer_uint8)0;
240 : }
241 0 : 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 0 : return (homer_uint8)8;
246 : }
247 0 : 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 0 : return (homer_uint8)4;
252 : }
253 0 : 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 0 : return (homer_uint8)2;
258 : }
259 0 : return 1;
260 0 : }
261 :
262 : homer_uint8 AliHLTHOMERWriter::DetermineDoubleAlignment()
263 : {
264 : // see header file for class documentation
265 0 : AliHLTHOMERWriterAlignmentDoubleTestStructure test;
266 0 : 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 0 : return ~(homer_uint8)0;
270 : }
271 0 : 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 0 : return (homer_uint8)8;
276 : }
277 0 : 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 0 : return (homer_uint8)4;
282 : }
283 0 : 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 0 : return (homer_uint8)2;
288 : }
289 0 : return 1;
290 0 : }
291 :
292 : homer_uint8 AliHLTHOMERWriter::DetermineFloatAlignment()
293 : {
294 : // see header file for class documentation
295 0 : AliHLTHOMERWriterAlignmentFloatTestStructure test;
296 0 : 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 0 : return ~(homer_uint8)0;
300 : }
301 0 : 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 0 : return (homer_uint8)8;
306 : }
307 0 : 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 0 : return (homer_uint8)4;
312 : }
313 0 : 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 0 : return (homer_uint8)2;
318 : }
319 0 : return 1;
320 0 : }
321 :
322 : AliHLTHOMERWriter* AliHLTHOMERWriterCreate()
323 : {
324 : // see header file for function documentation
325 0 : return new AliHLTHOMERWriter();
326 0 : }
327 :
328 : void AliHLTHOMERWriterDelete(AliHLTHOMERWriter* pInstance)
329 : {
330 : // see header file for function documentation
331 0 : if (pInstance) delete pInstance;
332 0 : }
333 :
334 :
335 : /*
336 : ***************************************************************************
337 : **
338 : ** $Author$ - Initial Version by Timm Morten Steinbeck
339 : **
340 : ** $Id$
341 : **
342 : ***************************************************************************
343 : */
|