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 class AliHLTMonitoringReader
39 AliHLTMonitoringReader() {};
40 virtual ~AliHLTMonitoringReader() {};
42 /* Read in the next available event */
43 virtual int ReadNextEvent() = 0;
44 /* Read in the next available event, wait max. timeout microsecs. */
45 virtual int ReadNextEvent( unsigned long timeout ) = 0;
47 /* Return the type of the current event */
48 virtual homer_uint64 GetEventType() const = 0;
50 /* Return the ID of the current event */
51 virtual homer_uint64 GetEventID() const = 0;
53 /* Return the number of data blocks in the current event */
54 virtual unsigned long GetBlockCnt() const = 0;
56 /* Return the size (in bytes) of the current event's data
57 block with the given block index (starting at 0). */
58 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const = 0;
59 /* Return a pointer to the start of the current event's data
60 block with the given block index (starting at 0). */
61 virtual const void* GetBlockData( unsigned long ndx ) const = 0;
62 /* Return IP address or hostname of node which sent the
63 current event's data block with the given block index
65 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const = 0;
66 /* Return byte order of the data stored in the
67 current event's data block with the given block
68 index (starting at 0).
69 0 is unknown alignment,
72 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const = 0;
73 /* Return the alignment (in bytes) of the given datatype
74 in the data stored in the current event's data block
75 with the given block index (starting at 0).
76 Possible values for the data type are
84 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const = 0;
86 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const = 0;
88 /* Return the type of the data in the current event's data
89 block with the given block index (starting at 0). */
90 virtual homer_uint64 GetBlockDataType( unsigned long ndx ) const = 0;
91 /* Return the origin of the data in the current event's data
92 block with the given block index (starting at 0). */
93 virtual homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const = 0;
94 /* Return a specification of the data in the current event's data
95 block with the given block index (starting at 0). */
96 virtual homer_uint32 GetBlockDataSpec( unsigned long ndx ) const = 0;
98 /* Find the next data block in the current event with the given
99 data type, origin, and specification. Returns the block's
101 virtual unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
102 homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
104 /* Find the next data block in the current event with the given
105 data type, origin, and specification. Returns the block's
107 virtual unsigned long FindBlockNdx( char type[8], char origin[4],
108 homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
110 ClassDef(AliHLTMonitoringReader,1);
116 class AliHLTHOMERReader: public AliHLTMonitoringReader
123 /* Constructors & destructors, HOMER specific */
124 /* For reading from a TCP port */
125 AliHLTHOMERReader( const char* hostname, unsigned short port );
126 /* For reading from multiple TCP ports */
127 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
128 /* For reading from a System V shared memory segment */
129 AliHLTHOMERReader( key_t shmKey, int shmSize );
130 /* For reading from multiple System V shared memory segments */
131 AliHLTHOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
132 /* For reading from multiple TCP ports and multiple System V shared memory segments */
133 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports,
134 unsigned int shmCnt, key_t* shmKey, int* shmSize );
135 /* For reading from a buffer */
136 AliHLTHOMERReader( const void* pBuffer, int size );
137 virtual ~AliHLTHOMERReader();
139 /* Return the status of the connection as established by one of the constructors.
140 0 means connection is ok, non-zero specifies the type of error that occured. */
141 int GetConnectionStatus() const
143 return fConnectionStatus;
146 /* Return the index of the connection for which an error given by the above
148 unsigned int GetErrorConnectionNdx() const
150 return fErrorConnection;
153 void SetEventRequestAdvanceTime( unsigned long time )
155 // advance time in us
156 fEventRequestAdvanceTime = time;
159 /* Defined in AliHLTMonitoringReader */
160 /* Read in the next available event */
161 virtual int ReadNextEvent();
162 /* Read in the next available event */
163 virtual int ReadNextEvent( unsigned long timeout );
165 /* Return the type of the current event */
166 virtual homer_uint64 GetEventType() const
168 return fCurrentEventType;
171 /* Return the ID of the current event */
172 virtual homer_uint64 GetEventID() const
174 return fCurrentEventID;
177 /* Return the number of data blocks in the current event */
178 virtual unsigned long GetBlockCnt() const
183 /* Return the size (in bytes) of the current event's data
184 block with the given block index (starting at 0). */
185 virtual const void* GetBlockData( unsigned long ndx ) const;
186 /* Return a pointer to the start of the current event's data
187 block with the given block index (starting at 0). */
188 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const;
189 /* Return IP address or hostname of node which sent the
190 current event's data block with the given block index
192 For HOMER this is the ID of the node on which the subscriber
193 that provided this data runs/ran. */
194 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const;
195 /* Return byte order of the data stored in the
196 current event's data block with the given block
197 index (starting at 0).
198 0 is unknown alignment,
201 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const;
202 /* Return the alignment (in bytes) of the given datatype
203 in the data stored in the current event's data block
204 with the given block index (starting at 0).
205 Possible values for the data type are
213 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const;
215 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
218 /* Return the type of the data in the current event's data
219 block with the given block index (starting at 0). */
220 homer_uint64 GetBlockDataType( unsigned long ndx ) const;
221 /* Return the origin of the data in the current event's data
222 block with the given block index (starting at 0). */
223 homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const;
224 /* Return a specification of the data in the current event's data
225 block with the given block index (starting at 0). */
226 homer_uint32 GetBlockDataSpec( unsigned long ndx ) const;
228 /* Find the next data block in the current event with the given
229 data type, origin, and specification. Returns the block's
231 unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
232 homer_uint32 spec, unsigned long startNdx=0 ) const;
234 /* Find the next data block in the current event with the given
235 data type, origin, and specification. Returns the block's
237 unsigned long FindBlockNdx( char type[8], char origin[4],
238 homer_uint32 spec, unsigned long startNdx=0 ) const;
240 /* Return the ID of the node that actually produced this data block.
241 This may be different from the node which sent the data to this
242 monitoring object as returned by GetBlockSendNodeID. */
243 const char* GetBlockCreateNodeID( unsigned long ndx ) const;
247 enum DataSourceType { kUndef=0, kTCP, kShm, kBuf};
250 DataSourceType fType; // source type (TCP or Shm)
251 unsigned fNdx; // This source's index
252 const char* fHostname; // Filled for both Shm and TCP
253 unsigned short fTCPPort; // port if type TCP
254 key_t fShmKey; // shm key if type Shm
255 int fShmSize; // shm size if type Shm
256 int fTCPConnection; // File descriptor for the TCP connection
257 int fShmID; // ID of the shared memory area
258 void* fShmPtr; // Pointer to shared memory area
259 void* fData; // Pointer to data read in for current event from this source
260 unsigned long fDataSize; // Size of data (to be) read in for current event from this source
261 unsigned long fDataRead; // Data actually read for current event
266 bool AllocDataSources( unsigned int sourceCnt );
267 int AddDataSource( const char* hostname, unsigned short port, DataSource& source );
268 int AddDataSource( key_t shmKey, int shmSize, DataSource& source );
269 int AddDataSource( void* pBuffer, int size, DataSource& source );
270 void FreeDataSources();
271 int FreeShmDataSource( DataSource& source );
272 int FreeTCPDataSource( DataSource& source );
273 int ReadNextEvent( bool useTimeout, unsigned long timeout );
274 void ReleaseCurrentEvent();
275 int TriggerTCPSource( DataSource& source, bool useTimeout, unsigned long timeout );
276 int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout ) const;
277 int ReadDataFromTCPSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
278 int ReadDataFromShmSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
279 int ParseSourceData( DataSource& source );
280 int ReAllocBlocks( unsigned long newCnt );
281 homer_uint64 GetSourceEventID( DataSource& source );
282 homer_uint64 GetSourceEventType( DataSource& source );
283 homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
285 homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
290 unsigned int fSource; // Index of originating data source
291 void* fData; // pointer to data
292 unsigned long fLength; // buffer length
293 homer_uint64* fMetaData; // Pointer to meta data describing data itself.
294 const char* fOriginatingNodeID; // node id from which the data originates
297 /** type of the current event */
298 homer_uint64 fCurrentEventType; //!transient
299 /** ID of the current event */
300 homer_uint64 fCurrentEventID; //!transient
301 /** no of blocks currently used */
302 unsigned long fBlockCnt; //!transient
303 /** available space in the block array */
304 unsigned long fMaxBlockCnt; //!transient
306 DataBlock* fBlocks; //!transient
308 /** total no of data sources */
309 unsigned int fDataSourceCnt; //!transient
310 /** no of TCP data sources */
311 unsigned int fTCPDataSourceCnt; //!transient
312 /** no of Shm data sources */
313 unsigned int fShmDataSourceCnt; //!transient
314 /** available space in the sources array */
315 unsigned int fDataSourceMaxCnt; //!transient
316 /** array of data source descriptions */
317 DataSource* fDataSources; //!transient
319 /** status of the connection */
320 int fConnectionStatus; //!transient
321 /** flag an error for */
322 unsigned fErrorConnection; //!transient
325 unsigned long fEventRequestAdvanceTime; //!transient
327 /** copy constructor prohibited */
328 AliHLTHOMERReader(const AliHLTHOMERReader&);
329 /** assignment operator prohibited */
330 AliHLTHOMERReader& operator=(const AliHLTHOMERReader&);
333 ClassDef(AliHLTHOMERReader,2);
337 /** defined for backward compatibility */
338 typedef AliHLTMonitoringReader MonitoringReader;
339 /** defined for backward compatibility */
340 typedef AliHLTHOMERReader HOMERReader;
342 // external interface of the HOMER reader
343 #define ALIHLTHOMERREADER_CREATE_FROM_TCPPORT "AliHLTHOMERReaderCreateFromTCPPort"
344 #define ALIHLTHOMERREADER_CREATE_FROM_TCPPORTS "AliHLTHOMERReaderCreateFromTCPPorts"
345 #define ALIHLTHOMERREADER_CREATE_FROM_BUFFER "AliHLTHOMERReaderCreateFromBuffer"
346 #define ALIHLTHOMERREADER_DELETE "AliHLTHOMERReaderDelete"
352 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPort_t)(const char* hostname, unsigned short port );
353 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPorts_t)(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
354 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromBuffer_t)(const void* pBuffer, int size);
355 typedef void (*AliHLTHOMERReaderDelete_t)(AliHLTHOMERReader* pInstance);
358 * Create instance of HOMER reader working on a TCP port.
360 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPort(const char* hostname, unsigned short port );
363 * Create instance of HOMER reader working on multiple TCP ports.
365 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPorts(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
368 * Create instance of HOMER reader working on buffer.
370 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer(const void* pBuffer, int size);
373 * Delete instance of HOMER reader.
375 void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance);
380 #endif /* AliHLTHOMERREADER_H */