2 #ifndef AliHLTHOMERREADER_H
3 #define AliHLTHOMERREADER_H
4 /* This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * See cxx source for full Copyright notice */
8 /** @file AliHLTHOMERReader.h
11 @brief HLT Online Monitoring Environment including ROOT - Reader
12 @note migrated from PubSub HLT-stable-20070905.141318 (rev 2375) */
14 // see below for class documentation
16 // refer to README to build package
18 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
23 #include "AliHLTHOMERData.h"
29 * @class AliHLTMonitoringReader
30 * The class provides a virtual interface for the HOMER reader.
31 * Used for dynamic generation of HOMER readers and dynamic loading of
32 * the libAliHLTHOMER library.
33 * @see AliHLTHOMERLibManager
35 * @ingroup alihlt_homer
37 class AliHLTMonitoringReader
41 AliHLTMonitoringReader() {};
42 virtual ~AliHLTMonitoringReader() {};
44 /* Return the status of the connection as established by one of the constructors.
45 0 means connection is ok, non-zero specifies the type of error that occured. */
46 virtual int GetConnectionStatus() const = 0;
48 /* Return the index of the connection for which an error given by the above
50 virtual unsigned int GetErrorConnectionNdx() const = 0;
52 /* Read in the next available event */
53 virtual int ReadNextEvent() = 0;
54 /* Read in the next available event, wait max. timeout microsecs. */
55 virtual int ReadNextEvent( unsigned long timeout ) = 0;
57 /* Return the type of the current event */
58 virtual homer_uint64 GetEventType() const = 0;
60 /* Return the ID of the current event */
61 virtual homer_uint64 GetEventID() const = 0;
63 /* Return the number of data blocks in the current event */
64 virtual unsigned long GetBlockCnt() const = 0;
66 /* Return the size (in bytes) of the current event's data
67 block with the given block index (starting at 0). */
68 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const = 0;
69 /* Return a pointer to the start of the current event's data
70 block with the given block index (starting at 0). */
71 virtual const void* GetBlockData( unsigned long ndx ) const = 0;
72 /* Return IP address or hostname of node which sent the
73 current event's data block with the given block index
75 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const = 0;
76 /* Return byte order of the data stored in the
77 current event's data block with the given block
78 index (starting at 0).
79 0 is unknown alignment,
82 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const = 0;
83 /* Return the alignment (in bytes) of the given datatype
84 in the data stored in the current event's data block
85 with the given block index (starting at 0).
86 Possible values for the data type are
94 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const = 0;
96 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const = 0;
98 /* Return the type of the data in the current event's data
99 block with the given block index (starting at 0). */
100 virtual homer_uint64 GetBlockDataType( unsigned long ndx ) const = 0;
101 /* Return the origin of the data in the current event's data
102 block with the given block index (starting at 0). */
103 virtual homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const = 0;
104 /* Return a specification of the data in the current event's data
105 block with the given block index (starting at 0). */
106 virtual homer_uint32 GetBlockDataSpec( unsigned long ndx ) const = 0;
108 /* Find the next data block in the current event with the given
109 data type, origin, and specification. Returns the block's
111 virtual unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
112 homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
114 /* Find the next data block in the current event with the given
115 data type, origin, and specification. Returns the block's
117 virtual unsigned long FindBlockNdx( char type[8], char origin[4],
118 homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
120 ClassDef(AliHLTMonitoringReader,1);
126 class AliHLTHOMERReader: public AliHLTMonitoringReader
133 /* Constructors & destructors, HOMER specific */
134 /* For reading from a TCP port */
135 AliHLTHOMERReader( const char* hostname, unsigned short port );
136 /* For reading from multiple TCP ports */
137 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
138 /* For reading from a System V shared memory segment */
139 AliHLTHOMERReader( key_t shmKey, int shmSize );
140 /* For reading from multiple System V shared memory segments */
141 AliHLTHOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
142 /* For reading from multiple TCP ports and multiple System V shared memory segments */
143 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports,
144 unsigned int shmCnt, key_t* shmKey, int* shmSize );
145 /* For reading from a buffer */
146 AliHLTHOMERReader( const void* pBuffer, int size );
147 virtual ~AliHLTHOMERReader();
149 /* Return the status of the connection as established by one of the constructors.
150 0 means connection is ok, non-zero specifies the type of error that occured. */
151 int GetConnectionStatus() const
153 return fConnectionStatus;
156 /* Return the index of the connection for which an error given by the above
158 unsigned int GetErrorConnectionNdx() const
160 return fErrorConnection;
163 void SetEventRequestAdvanceTime( unsigned long time )
165 // advance time in us
166 fEventRequestAdvanceTime = time;
169 /* Defined in AliHLTMonitoringReader */
170 /* Read in the next available event */
171 virtual int ReadNextEvent();
172 /* Read in the next available event */
173 virtual int ReadNextEvent( unsigned long timeout );
175 /* Return the type of the current event */
176 virtual homer_uint64 GetEventType() const
178 return fCurrentEventType;
181 /* Return the ID of the current event */
182 virtual homer_uint64 GetEventID() const
184 return fCurrentEventID;
187 /* Return the number of data blocks in the current event */
188 virtual unsigned long GetBlockCnt() const
193 /* Return the size (in bytes) of the current event's data
194 block with the given block index (starting at 0). */
195 virtual const void* GetBlockData( unsigned long ndx ) const;
196 /* Return a pointer to the start of the current event's data
197 block with the given block index (starting at 0). */
198 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const;
199 /* Return IP address or hostname of node which sent the
200 current event's data block with the given block index
202 For HOMER this is the ID of the node on which the subscriber
203 that provided this data runs/ran. */
204 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const;
205 /* Return byte order of the data stored in the
206 current event's data block with the given block
207 index (starting at 0).
208 0 is unknown alignment,
211 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const;
212 /* Return the alignment (in bytes) of the given datatype
213 in the data stored in the current event's data block
214 with the given block index (starting at 0).
215 Possible values for the data type are
223 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const;
225 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
228 /* Return the type of the data in the current event's data
229 block with the given block index (starting at 0). */
230 homer_uint64 GetBlockDataType( unsigned long ndx ) const;
231 /* Return the origin of the data in the current event's data
232 block with the given block index (starting at 0). */
233 homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const;
234 /* Return a specification of the data in the current event's data
235 block with the given block index (starting at 0). */
236 homer_uint32 GetBlockDataSpec( unsigned long ndx ) const;
238 /* Find the next data block in the current event with the given
239 data type, origin, and specification. Returns the block's
241 unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
242 homer_uint32 spec, unsigned long startNdx=0 ) const;
244 /* Find the next data block in the current event with the given
245 data type, origin, and specification. Returns the block's
247 unsigned long FindBlockNdx( char type[8], char origin[4],
248 homer_uint32 spec, unsigned long startNdx=0 ) const;
250 /* Return the ID of the node that actually produced this data block.
251 This may be different from the node which sent the data to this
252 monitoring object as returned by GetBlockSendNodeID. */
253 const char* GetBlockCreateNodeID( unsigned long ndx ) const;
257 enum DataSourceType { kUndef=0, kTCP, kShm, kBuf};
260 DataSourceType fType; // source type (TCP or Shm)
261 unsigned fNdx; // This source's index
262 const char* fHostname; // Filled for both Shm and TCP
263 unsigned short fTCPPort; // port if type TCP
264 key_t fShmKey; // shm key if type Shm
265 int fShmSize; // shm size if type Shm
266 int fTCPConnection; // File descriptor for the TCP connection
267 int fShmID; // ID of the shared memory area
268 void* fShmPtr; // Pointer to shared memory area
269 void* fData; // Pointer to data read in for current event from this source
270 unsigned long fDataSize; // Size of data (to be) read in for current event from this source
271 unsigned long fDataRead; // Data actually read for current event
276 bool AllocDataSources( unsigned int sourceCnt );
277 int AddDataSource( const char* hostname, unsigned short port, DataSource& source );
278 int AddDataSource( key_t shmKey, int shmSize, DataSource& source );
279 int AddDataSource( void* pBuffer, int size, DataSource& source );
280 void FreeDataSources();
281 int FreeShmDataSource( DataSource& source );
282 int FreeTCPDataSource( DataSource& source );
283 int ReadNextEvent( bool useTimeout, unsigned long timeout );
284 void ReleaseCurrentEvent();
285 int TriggerTCPSource( DataSource& source, bool useTimeout, unsigned long timeout );
286 int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout ) const;
287 int ReadDataFromTCPSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
288 int ReadDataFromShmSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
289 int ParseSourceData( DataSource& source );
290 int ReAllocBlocks( unsigned long newCnt );
291 homer_uint64 GetSourceEventID( DataSource& source );
292 homer_uint64 GetSourceEventType( DataSource& source );
293 homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
295 homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
300 unsigned int fSource; // Index of originating data source
301 void* fData; // pointer to data
302 unsigned long fLength; // buffer length
303 homer_uint64* fMetaData; // Pointer to meta data describing data itself.
304 const char* fOriginatingNodeID; // node id from which the data originates
307 /** type of the current event */
308 homer_uint64 fCurrentEventType; //!transient
309 /** ID of the current event */
310 homer_uint64 fCurrentEventID; //!transient
311 /** no of blocks currently used */
312 unsigned long fBlockCnt; //!transient
313 /** available space in the block array */
314 unsigned long fMaxBlockCnt; //!transient
316 DataBlock* fBlocks; //!transient
318 /** total no of data sources */
319 unsigned int fDataSourceCnt; //!transient
320 /** no of TCP data sources */
321 unsigned int fTCPDataSourceCnt; //!transient
322 /** no of Shm data sources */
323 unsigned int fShmDataSourceCnt; //!transient
324 /** available space in the sources array */
325 unsigned int fDataSourceMaxCnt; //!transient
326 /** array of data source descriptions */
327 DataSource* fDataSources; //!transient
329 /** status of the connection */
330 int fConnectionStatus; //!transient
331 /** flag an error for */
332 unsigned fErrorConnection; //!transient
335 unsigned long fEventRequestAdvanceTime; //!transient
337 /** copy constructor prohibited */
338 AliHLTHOMERReader(const AliHLTHOMERReader&);
339 /** assignment operator prohibited */
340 AliHLTHOMERReader& operator=(const AliHLTHOMERReader&);
343 ClassDef(AliHLTHOMERReader,2);
347 /** defined for backward compatibility */
348 typedef AliHLTMonitoringReader MonitoringReader;
349 /** defined for backward compatibility */
350 typedef AliHLTHOMERReader HOMERReader;
352 // external interface of the HOMER reader
353 #define ALIHLTHOMERREADER_CREATE_FROM_TCPPORT "AliHLTHOMERReaderCreateFromTCPPort"
354 #define ALIHLTHOMERREADER_CREATE_FROM_TCPPORTS "AliHLTHOMERReaderCreateFromTCPPorts"
355 #define ALIHLTHOMERREADER_CREATE_FROM_BUFFER "AliHLTHOMERReaderCreateFromBuffer"
356 #define ALIHLTHOMERREADER_DELETE "AliHLTHOMERReaderDelete"
362 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPort_t)(const char* hostname, unsigned short port );
363 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPorts_t)(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
364 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromBuffer_t)(const void* pBuffer, int size);
365 typedef void (*AliHLTHOMERReaderDelete_t)(AliHLTHOMERReader* pInstance);
368 * Create instance of HOMER reader working on a TCP port.
370 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPort(const char* hostname, unsigned short port );
373 * Create instance of HOMER reader working on multiple TCP ports.
375 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPorts(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
378 * Create instance of HOMER reader working on buffer.
380 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer(const void* pBuffer, int size);
383 * Delete instance of HOMER reader.
385 void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance);
390 #endif /* AliHLTHOMERREADER_H */