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"
28 class AliHLTMonitoringReader
32 AliHLTMonitoringReader() {};
33 virtual ~AliHLTMonitoringReader() {};
35 /* Read in the next available event */
36 virtual int ReadNextEvent() = 0;
37 /* Read in the next available event, wait max. timeout microsecs. */
38 virtual int ReadNextEvent( unsigned long timeout ) = 0;
40 /* Return the type of the current event */
41 virtual homer_uint64 GetEventType() const = 0;
43 /* Return the ID of the current event */
44 virtual homer_uint64 GetEventID() const = 0;
46 /* Return the number of data blocks in the current event */
47 virtual unsigned long GetBlockCnt() const = 0;
49 /* Return the size (in bytes) of the current event's data
50 block with the given block index (starting at 0). */
51 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const = 0;
52 /* Return a pointer to the start of the current event's data
53 block with the given block index (starting at 0). */
54 virtual const void* GetBlockData( unsigned long ndx ) const = 0;
55 /* Return IP address or hostname of node which sent the
56 current event's data block with the given block index
58 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const = 0;
59 /* Return byte order of the data stored in the
60 current event's data block with the given block
61 index (starting at 0).
62 0 is unknown alignment,
65 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const = 0;
66 /* Return the alignment (in bytes) of the given datatype
67 in the data stored in the current event's data block
68 with the given block index (starting at 0).
69 Possible values for the data type are
77 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const = 0;
79 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const = 0;
82 ClassDef(AliHLTMonitoringReader,1);
88 class AliHLTHOMERReader: public AliHLTMonitoringReader
95 /* Constructors & destructors, HOMER specific */
96 /* For reading from a TCP port */
97 AliHLTHOMERReader( const char* hostname, unsigned short port );
98 /* For reading from multiple TCP ports */
99 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
100 /* For reading from a System V shared memory segment */
101 AliHLTHOMERReader( key_t shmKey, int shmSize );
102 /* For reading from multiple System V shared memory segments */
103 AliHLTHOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
104 /* For reading from multiple TCP ports and multiple System V shared memory segments */
105 AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports,
106 unsigned int shmCnt, key_t* shmKey, int* shmSize );
107 virtual ~AliHLTHOMERReader();
109 /* Return the status of the connection as established by one of the constructors.
110 0 means connection is ok, non-zero specifies the type of error that occured. */
111 int GetConnectionStatus() const
113 return fConnectionStatus;
116 /* Return the index of the connection for which an error given by the above
118 unsigned int GetErrorConnectionNdx() const
120 return fErrorConnection;
123 void SetEventRequestAdvanceTime( unsigned long time )
125 // advance time in us
126 fEventRequestAdvanceTime = time;
129 /* Defined in AliHLTMonitoringReader */
130 /* Read in the next available event */
131 virtual int ReadNextEvent();
132 /* Read in the next available event */
133 virtual int ReadNextEvent( unsigned long timeout );
135 /* Return the type of the current event */
136 virtual homer_uint64 GetEventType() const
138 return fCurrentEventType;
141 /* Return the ID of the current event */
142 virtual homer_uint64 GetEventID() const
144 return fCurrentEventID;
147 /* Return the number of data blocks in the current event */
148 virtual unsigned long GetBlockCnt() const
153 /* Return the size (in bytes) of the current event's data
154 block with the given block index (starting at 0). */
155 virtual const void* GetBlockData( unsigned long ndx ) const;
156 /* Return a pointer to the start of the current event's data
157 block with the given block index (starting at 0). */
158 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const;
159 /* Return IP address or hostname of node which sent the
160 current event's data block with the given block index
162 For HOMER this is the ID of the node on which the subscriber
163 that provided this data runs/ran. */
164 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const;
165 /* Return byte order of the data stored in the
166 current event's data block with the given block
167 index (starting at 0).
168 0 is unknown alignment,
171 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const;
172 /* Return the alignment (in bytes) of the given datatype
173 in the data stored in the current event's data block
174 with the given block index (starting at 0).
175 Possible values for the data type are
183 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const;
185 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
188 /* Return the type of the data in the current event's data
189 block with the given block index (starting at 0). */
190 homer_uint64 GetBlockDataType( unsigned long ndx ) const;
191 /* Return the origin of the data in the current event's data
192 block with the given block index (starting at 0). */
193 homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const;
194 /* Return a specification of the data in the current event's data
195 block with the given block index (starting at 0). */
196 homer_uint32 GetBlockDataSpec( unsigned long ndx ) const;
198 /* Find the next data block in the current event with the given
199 data type, origin, and specification. Returns the block's
201 unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
202 homer_uint32 spec, unsigned long startNdx=0 ) const;
204 /* Find the next data block in the current event with the given
205 data type, origin, and specification. Returns the block's
207 unsigned long FindBlockNdx( char type[8], char origin[4],
208 homer_uint32 spec, unsigned long startNdx=0 ) const;
210 /* Return the ID of the node that actually produced this data block.
211 This may be different from the node which sent the data to this
212 monitoring object as returned by GetBlockSendNodeID. */
213 const char* GetBlockCreateNodeID( unsigned long ndx ) const;
217 enum DataSourceType { kUndef=0, kTCP, kShm };
220 DataSource() { fType = kUndef; };
221 DataSourceType fType; // source type (TCP or Shm)
222 unsigned fNdx; // This source's index
223 const char* fHostname; // Filled for both Shm and TCP
224 unsigned short fTCPPort; // port if type TCP
225 key_t fShmKey; // shm key if type Shm
226 int fShmSize; // shm size if type Shm
227 int fTCPConnection; // File descriptor for the TCP connection
228 int fShmID; // ID of the shared memory area
229 void* fShmPtr; // Pointer to shared memory area
230 void* fData; // Pointer to data read in for current event from this source
231 unsigned long fDataSize; // Size of data (to be) read in for current event from this source
232 unsigned long fDataRead; // Data actually read for current event
237 bool AllocDataSources( unsigned int sourceCnt );
238 int AddDataSource( const char* hostname, unsigned short port, DataSource& source );
239 int AddDataSource( key_t shmKey, int shmSize, DataSource& source );
240 void FreeDataSources();
241 int FreeShmDataSource( DataSource& source );
242 int FreeTCPDataSource( DataSource& source );
243 int ReadNextEvent( bool useTimeout, unsigned long timeout );
244 void ReleaseCurrentEvent();
245 int TriggerTCPSource( DataSource& source, bool useTimeout, unsigned long timeout );
246 int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout );
247 int ReadDataFromTCPSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
248 int ReadDataFromShmSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
249 int ParseSourceData( DataSource& source );
250 int ReAllocBlocks( unsigned long newCnt );
251 homer_uint64 GetSourceEventID( DataSource& source );
252 homer_uint64 GetSourceEventType( DataSource& source );
253 homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
255 homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
260 unsigned int fSource; // Index of originating data source
261 void* fData; // pointer to data
262 unsigned long fLength; // buffer length
263 homer_uint64* fMetaData; // Pointer to meta data describing data itself.
264 const char* fOriginatingNodeID; // node id from which the data originates
267 /** type of the current event */
268 homer_uint64 fCurrentEventType; //!transient
269 /** ID of the current event */
270 homer_uint64 fCurrentEventID; //!transient
271 /** no of blocks currently used */
272 unsigned long fBlockCnt; //!transient
273 /** available space in the block array */
274 unsigned long fMaxBlockCnt; //!transient
276 DataBlock* fBlocks; //!transient
278 /** total no of data sources */
279 unsigned int fDataSourceCnt; //!transient
280 /** no of TCP data sources */
281 unsigned int fTCPDataSourceCnt; //!transient
282 /** no of Shm data sources */
283 unsigned int fShmDataSourceCnt; //!transient
284 /** available space in the sources array */
285 unsigned int fDataSourceMaxCnt; //!transient
286 /** array of data source descriptions */
287 DataSource* fDataSources; //!transient
289 /** status of the connection */
290 int fConnectionStatus; //!transient
291 /** flag an error for */
292 unsigned fErrorConnection; //!transient
295 unsigned long fEventRequestAdvanceTime; //!transient
297 /** copy constructor prohibited */
298 AliHLTHOMERReader(const AliHLTHOMERReader&);
299 /** assignment operator prohibited */
300 AliHLTHOMERReader& operator=(const AliHLTHOMERReader&);
303 ClassDef(AliHLTHOMERReader,2);
307 /** defined for backward compatibility */
308 typedef AliHLTMonitoringReader MonitoringReader;
309 /** defined for backward compatibility */
310 typedef AliHLTHOMERReader HOMERReader;
312 // external interface of the HOMER reader
313 #define ALIHLTHOMERREADER_CREATE_FROM_BUFFER "AliHLTHOMERReaderCreateFromBuffer"
314 #define ALIHLTHOMERREADER_DELETE "AliHLTHOMERReaderDelete"
320 typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromBuffer_t)(const void* pBuffer, int size);
321 typedef void (*AliHLTHOMERReaderDelete_t)(AliHLTHOMERReader* pInstance);
323 * Create instance of HOMER reader.
325 AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer();
328 * Delete instance of HOMER reader.
330 void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance);
335 #endif /* AliHLTHOMERREADER_H */