1 /************************************************************************
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
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.
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.
21 *************************************************************************/
24 ***************************************************************************
26 ** $Author$ - Initial Version by Timm Morten Steinbeck
30 ***************************************************************************
33 /** @file AliHLTHOMERWriter.cxx
34 @author Timm Steinbeck
36 @brief HLT Online Monitoring Environment including ROOT - Writer
37 @note migrated from PubSub HLT-stable-20070905.141318 (rev 2375) */
39 // see header file for class documentation
41 // refer to README to build package
43 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45 #include "AliHLTHOMERWriter.h"
50 HOMERWriter::HOMERWriter()
55 // Writer implementation of the HOMER interface.
56 // The HLT Monitoring Environment including ROOT is
57 // a native interface to ship out data from the HLT chain.
58 // See pdf document shiped with the package
59 // for class documentation and tutorial.
63 HOMERWriter::~HOMERWriter()
65 // see header file for class documentation
68 void HOMERWriter::Clear()
70 // see header file for class documentation
75 void HOMERWriter::AddBlock( const void* descriptor, const void* data )
77 // see header file for class documentation
79 memcpy( bd.fDescriptor, descriptor, HOMERBlockDescriptor::GetHOMERBlockDescriptorSize() );
81 HOMERBlockDescriptor hbd( &bd.fDescriptor );
82 hbd.SetBlockOffset( fDataOffset );
83 fDataOffset += hbd.GetBlockSize();
84 fBlocks.push_back( bd );
87 homer_uint32 HOMERWriter::GetTotalMemorySize( bool includeData )
89 // see header file for class documentation
91 return fDataOffset + HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
93 return HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
96 void HOMERWriter::Copy( void* destination, homer_uint64 eventType, homer_uint64 eventNr, homer_uint64 statusFlags, homer_uint64 nodeID, bool includeData )
98 // see header file for class documentation
99 HOMERBlockDescriptor homerBlock;
100 homer_uint8* bd = reinterpret_cast<homer_uint8*>( destination );
102 gettimeofday( &now, NULL );
103 homerBlock.UseHeader( bd );
104 homerBlock.Initialize();
105 homerBlock.SetUInt64Alignment( HOMERWriter::DetermineUInt64Alignment() );
106 homerBlock.SetUInt32Alignment( HOMERWriter::DetermineUInt32Alignment() );
107 homerBlock.SetUInt16Alignment( HOMERWriter::DetermineUInt16Alignment() );
108 homerBlock.SetUInt8Alignment( HOMERWriter::DetermineUInt8Alignment() );
109 homerBlock.SetDoubleAlignment( HOMERWriter::DetermineDoubleAlignment() );
110 homerBlock.SetFloatAlignment( HOMERWriter::DetermineFloatAlignment() );
111 homerBlock.SetType( eventType );
112 homerBlock.SetSubType1( eventNr );
113 homerBlock.SetSubType2( fBlocks.size() );
114 homerBlock.SetBirth_s( now.tv_sec );
115 homerBlock.SetBirth_us( now.tv_usec );
116 homerBlock.SetProducerNode( nodeID );
117 homerBlock.SetBlockOffset( homerBlock.GetHeaderLength() );
118 homerBlock.SetBlockSize( HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*fBlocks.size() );
119 homerBlock.SetStatusFlags( statusFlags );
120 bd += homerBlock.GetHeaderLength();
122 //unsigned long dataOffset = HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
123 unsigned long dataOffset = homerBlock.GetBlockOffset() + homerBlock.GetBlockSize();
124 std::vector<TBlockData>::iterator iter, end;
125 iter = fBlocks.begin();
127 while ( iter != end )
129 homerBlock.UseHeader( iter->fDescriptor );
130 homerBlock.SetBlockOffset( homerBlock.GetBlockOffset()+dataOffset );
131 memcpy( bd, iter->fDescriptor, homerBlock.GetHeaderLength() );
132 bd += homerBlock.GetHeaderLength();
135 memcpy( ((homer_uint8*)destination)+homerBlock.GetBlockOffset(), iter->fData, homerBlock.GetBlockSize() );
141 homer_uint8 HOMERWriter::DetermineUInt64Alignment()
143 // see header file for class documentation
144 HOMERWriterAlignment64TestStructure test;
145 if ( (unsigned long)(&test.f64Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
147 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
148 return ~(homer_uint8)0;
150 if ( (unsigned long)(&test.f64Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
152 // The 64 bit element does not immedately follow the 32 bit element,
153 // therefore the alignment has to be greater than 4.
154 return (homer_uint8)8;
156 if ( (unsigned long)(&test.f64Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
158 // The 64 bit element does not immedately follow the 16 bit element,
159 // therefore the alignment has to be greater than 2.
160 return (homer_uint8)4;
162 if ( (unsigned long)(&test.f64Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
164 // The 64 bit element does not immedately follow the 8 bit element,
165 // therefore the alignment has to be greater than 1.
166 return (homer_uint8)2;
171 homer_uint8 HOMERWriter::DetermineUInt32Alignment()
173 // see header file for class documentation
174 HOMERWriterAlignment32TestStructure test;
175 if ( (unsigned long)(&test.f32Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
177 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
178 return ~(homer_uint8)0;
180 if ( (unsigned long)(&test.f32Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
182 // The 32 bit element does not immedately follow the 32 bit element,
183 // therefore the alignment has to be greater than 4.
184 return (homer_uint8)8;
186 if ( (unsigned long)(&test.f32Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
188 // The 32 bit element does not immedately follow the 16 bit element,
189 // therefore the alignment has to be greater than 2.
190 return (homer_uint8)4;
192 if ( (unsigned long)(&test.f32Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
194 // The 32 bit element does not immedately follow the 8 bit element,
195 // therefore the alignment has to be greater than 1.
196 return (homer_uint8)2;
201 homer_uint8 HOMERWriter::DetermineUInt16Alignment()
203 // see header file for class documentation
204 HOMERWriterAlignment16TestStructure test;
205 if ( (unsigned long)(&test.f16Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
207 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
208 return ~(homer_uint8)0;
210 if ( (unsigned long)(&test.f16Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
212 // The 16 bit element does not immedately follow the 32 bit element,
213 // therefore the alignment has to be greater than 4.
214 return (homer_uint8)8;
216 if ( (unsigned long)(&test.f16Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
218 // The 16 bit element does not immedately follow the 16 bit element,
219 // therefore the alignment has to be greater than 2.
220 return (homer_uint8)4;
222 if ( (unsigned long)(&test.f16Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
224 // The 16 bit element does not immedately follow the 8 bit element,
225 // therefore the alignment has to be greater than 1.
226 return (homer_uint8)2;
231 homer_uint8 HOMERWriter::DetermineUInt8Alignment()
233 // see header file for class documentation
234 HOMERWriterAlignment8TestStructure test;
235 if ( (unsigned long)(&test.f8Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
237 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
238 return ~(homer_uint8)0;
240 if ( (unsigned long)(&test.f8Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
242 // The 8 bit element does not immedately follow the 32 bit element,
243 // therefore the alignment has to be greater than 4.
244 return (homer_uint8)8;
246 if ( (unsigned long)(&test.f8Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
248 // The 8 bit element does not immedately follow the 16 bit element,
249 // therefore the alignment has to be greater than 2.
250 return (homer_uint8)4;
252 if ( (unsigned long)(&test.f8Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
254 // The 8 bit element does not immedately follow the 8 bit element,
255 // therefore the alignment has to be greater than 1.
256 return (homer_uint8)2;
261 homer_uint8 HOMERWriter::DetermineDoubleAlignment()
263 // see header file for class documentation
264 HOMERWriterAlignmentDoubleTestStructure test;
265 if ( (unsigned long)(&test.fDoubleTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
267 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
268 return ~(homer_uint8)0;
270 if ( (unsigned long)(&test.fDoubleTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
272 // The double element does not immedately follow the 32 bit element,
273 // therefore the alignment has to be greater than 4.
274 return (homer_uint8)8;
276 if ( (unsigned long)(&test.fDoubleTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
278 // The double element does not immedately follow the 16 bit element,
279 // therefore the alignment has to be greater than 2.
280 return (homer_uint8)4;
282 if ( (unsigned long)(&test.fDoubleTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
284 // The double element does not immedately follow the 8 bit element,
285 // therefore the alignment has to be greater than 1.
286 return (homer_uint8)2;
291 homer_uint8 HOMERWriter::DetermineFloatAlignment()
293 // see header file for class documentation
294 HOMERWriterAlignmentFloatTestStructure test;
295 if ( (unsigned long)(&test.fFloatTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
297 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
298 return ~(homer_uint8)0;
300 if ( (unsigned long)(&test.fFloatTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
302 // The float element does not immedately follow the 32 bit element,
303 // therefore the alignment has to be greater than 4.
304 return (homer_uint8)8;
306 if ( (unsigned long)(&test.fFloatTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
308 // The float element does not immedately follow the 16 bit element,
309 // therefore the alignment has to be greater than 2.
310 return (homer_uint8)4;
312 if ( (unsigned long)(&test.fFloatTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
314 // The float element does not immedately follow the 8 bit element,
315 // therefore the alignment has to be greater than 1.
316 return (homer_uint8)2;
324 ***************************************************************************
326 ** $Author$ - Initial Version by Timm Morten Steinbeck
330 ***************************************************************************