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
46 #include "AliHLTHOMERWriter.h"
51 AliHLTHOMERWriter::AliHLTHOMERWriter()
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.
64 AliHLTHOMERWriter::~AliHLTHOMERWriter()
66 // see header file for class documentation
69 void AliHLTHOMERWriter::Clear()
71 // see header file for class documentation
76 void AliHLTHOMERWriter::AddBlock( const void* descriptor, const void* data )
78 // see header file for class documentation
80 memcpy( bd.fDescriptor, descriptor, HOMERBlockDescriptor::GetHOMERBlockDescriptorSize() );
82 HOMERBlockDescriptor hbd( &bd.fDescriptor );
83 hbd.SetBlockOffset( fDataOffset );
84 fDataOffset += hbd.GetBlockSize();
85 fBlocks.push_back( bd );
88 homer_uint32 AliHLTHOMERWriter::GetTotalMemorySize( bool includeData )
90 // see header file for class documentation
92 return fDataOffset + HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
94 return HOMERBlockDescriptor::GetHOMERBlockDescriptorSize()*(fBlocks.size()+1);
97 void AliHLTHOMERWriter::Copy( void* destination, homer_uint64 eventType, homer_uint64 eventNr, homer_uint64 statusFlags, homer_uint64 nodeID, bool includeData )
99 // see header file for class documentation
100 HOMERBlockDescriptor homerBlock;
101 homer_uint8* bd = reinterpret_cast<homer_uint8*>( destination );
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();
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();
128 while ( iter != end )
130 homerBlock.UseHeader( iter->fDescriptor );
131 homerBlock.SetBlockOffset( homerBlock.GetBlockOffset()+dataOffset );
132 memcpy( bd, iter->fDescriptor, homerBlock.GetHeaderLength() );
133 bd += homerBlock.GetHeaderLength();
136 memcpy( ((homer_uint8*)destination)+homerBlock.GetBlockOffset(), iter->fData, homerBlock.GetBlockSize() );
142 homer_uint8 AliHLTHOMERWriter::DetermineUInt64Alignment()
144 // see header file for class documentation
145 AliHLTHOMERWriterAlignment64TestStructure test;
146 if ( (unsigned long)(&test.f64Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
148 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
149 return ~(homer_uint8)0;
151 if ( (unsigned long)(&test.f64Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
157 if ( (unsigned long)(&test.f64Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
163 if ( (unsigned long)(&test.f64Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
172 homer_uint8 AliHLTHOMERWriter::DetermineUInt32Alignment()
174 // see header file for class documentation
175 AliHLTHOMERWriterAlignment32TestStructure test;
176 if ( (unsigned long)(&test.f32Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
178 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
179 return ~(homer_uint8)0;
181 if ( (unsigned long)(&test.f32Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
187 if ( (unsigned long)(&test.f32Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
193 if ( (unsigned long)(&test.f32Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
202 homer_uint8 AliHLTHOMERWriter::DetermineUInt16Alignment()
204 // see header file for class documentation
205 AliHLTHOMERWriterAlignment16TestStructure test;
206 if ( (unsigned long)(&test.f16Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
208 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
209 return ~(homer_uint8)0;
211 if ( (unsigned long)(&test.f16Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
217 if ( (unsigned long)(&test.f16Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
223 if ( (unsigned long)(&test.f16Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
232 homer_uint8 AliHLTHOMERWriter::DetermineUInt8Alignment()
234 // see header file for class documentation
235 AliHLTHOMERWriterAlignment8TestStructure test;
236 if ( (unsigned long)(&test.f8Test64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
238 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
239 return ~(homer_uint8)0;
241 if ( (unsigned long)(&test.f8Test32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
247 if ( (unsigned long)(&test.f8Test16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
253 if ( (unsigned long)(&test.f8Test8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
262 homer_uint8 AliHLTHOMERWriter::DetermineDoubleAlignment()
264 // see header file for class documentation
265 AliHLTHOMERWriterAlignmentDoubleTestStructure test;
266 if ( (unsigned long)(&test.fDoubleTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
268 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
269 return ~(homer_uint8)0;
271 if ( (unsigned long)(&test.fDoubleTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
277 if ( (unsigned long)(&test.fDoubleTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
283 if ( (unsigned long)(&test.fDoubleTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
292 homer_uint8 AliHLTHOMERWriter::DetermineFloatAlignment()
294 // see header file for class documentation
295 AliHLTHOMERWriterAlignmentFloatTestStructure test;
296 if ( (unsigned long)(&test.fFloatTest64) != ((unsigned long)(&test.f64Fill))+sizeof(test.f64Fill) )
298 // Alignment is beyond 64 bit, this is, to the best of my knowledge, currently unheard of.
299 return ~(homer_uint8)0;
301 if ( (unsigned long)(&test.fFloatTest32) != ((unsigned long)(&test.f32Fill))+sizeof(test.f32Fill) )
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;
307 if ( (unsigned long)(&test.fFloatTest16) != ((unsigned long)(&test.f16Fill))+sizeof(test.f16Fill) )
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;
313 if ( (unsigned long)(&test.fFloatTest8) != ((unsigned long)(&test.f8Fill))+sizeof(test.f8Fill) )
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;
322 AliHLTHOMERWriter* AliHLTHOMERWriterCreate()
324 // see header file for function documentation
325 return new AliHLTHOMERWriter();
328 void AliHLTHOMERWriterDelete(AliHLTHOMERWriter* pInstance)
330 // see header file for function documentation
331 if (pInstance) delete pInstance;
336 ***************************************************************************
338 ** $Author$ - Initial Version by Timm Morten Steinbeck
342 ***************************************************************************