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 MonitoringReader
32 MonitoringReader() {};
33 virtual ~MonitoringReader() {};
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(MonitoringReader,1);
88 class HOMERReader: public MonitoringReader
95 /* Constructors & destructors, HOMER specific */
96 /* For reading from a TCP port */
97 HOMERReader( const char* hostname, unsigned short port );
98 /* For reading from multiple TCP ports */
99 HOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
100 /* For reading from a System V shared memory segment */
101 HOMERReader( key_t shmKey, int shmSize );
102 /* For reading from multiple System V shared memory segments */
103 HOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
104 /* For reading from multiple TCP ports and multiple System V shared memory segments */
105 HOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports,
106 unsigned int shmCnt, key_t* shmKey, int* shmSize );
107 virtual ~HOMERReader();
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 fEventRequestAdvanceTime = time;
128 /* Defined in MonitoringReader */
129 /* Read in the next available event */
130 virtual int ReadNextEvent();
131 /* Read in the next available event */
132 virtual int ReadNextEvent( unsigned long timeout );
134 /* Return the type of the current event */
135 virtual homer_uint64 GetEventType() const
137 return fCurrentEventType;
140 /* Return the ID of the current event */
141 virtual homer_uint64 GetEventID() const
143 return fCurrentEventID;
146 /* Return the number of data blocks in the current event */
147 virtual unsigned long GetBlockCnt() const
152 /* Return the size (in bytes) of the current event's data
153 block with the given block index (starting at 0). */
154 virtual const void* GetBlockData( unsigned long ndx ) const;
155 /* Return a pointer to the start of the current event's data
156 block with the given block index (starting at 0). */
157 virtual unsigned long GetBlockDataLength( unsigned long ndx ) const;
158 /* Return IP address or hostname of node which sent the
159 current event's data block with the given block index
161 For HOMER this is the ID of the node on which the subscriber
162 that provided this data runs/ran. */
163 virtual const char* GetBlockSendNodeID( unsigned long ndx ) const;
164 /* Return byte order of the data stored in the
165 current event's data block with the given block
166 index (starting at 0).
167 0 is unknown alignment,
170 virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const;
171 /* Return the alignment (in bytes) of the given datatype
172 in the data stored in the current event's data block
173 with the given block index (starting at 0).
174 Possible values for the data type are
182 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const;
184 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
187 /* Return the type of the data in the current event's data
188 block with the given block index (starting at 0). */
189 homer_uint64 GetBlockDataType( unsigned long ndx ) const;
190 /* Return the origin of the data in the current event's data
191 block with the given block index (starting at 0). */
192 homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const;
193 /* Return a specification of the data in the current event's data
194 block with the given block index (starting at 0). */
195 homer_uint32 GetBlockDataSpec( unsigned long ndx ) const;
197 /* Find the next data block in the current event with the given
198 data type, origin, and specification. Returns the block's
200 unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
201 homer_uint32 spec, unsigned long startNdx=0 ) const;
203 /* Find the next data block in the current event with the given
204 data type, origin, and specification. Returns the block's
206 unsigned long FindBlockNdx( char type[8], char origin[4],
207 homer_uint32 spec, unsigned long startNdx=0 ) const;
209 /* Return the ID of the node that actually produced this data block.
210 This may be different from the node which sent the data to this
211 monitoring object as returned by GetBlockSendNodeID. */
212 const char* GetBlockCreateNodeID( unsigned long ndx ) const;
216 enum DataSourceType { kUndef=0, kTCP, kShm };
219 DataSource() { fType = kUndef; };
220 DataSourceType fType; // source type (TCP or Shm)
221 unsigned fNdx; // This source's index
222 const char* fHostname; // Filled for both Shm and TCP
223 unsigned short fTCPPort; // port if type TCP
224 key_t fShmKey; // shm key if type Shm
225 int fShmSize; // shm size if type Shm
226 int fTCPConnection; // File descriptor for the TCP connection
227 int fShmID; // ID of the shared memory area
228 void* fShmPtr; // Pointer to shared memory area
229 void* fData; // Pointer to data read in for current event from this source
230 unsigned long fDataSize; // Size of data (to be) read in for current event from this source
231 unsigned long fDataRead; // Data actually read for current event
236 bool AllocDataSources( unsigned int sourceCnt );
237 int AddDataSource( const char* hostname, unsigned short port, DataSource& source );
238 int AddDataSource( key_t shmKey, int shmSize, DataSource& source );
239 void FreeDataSources();
240 int FreeShmDataSource( DataSource& source );
241 int FreeTCPDataSource( DataSource& source );
242 int ReadNextEvent( bool useTimeout, unsigned long timeout );
243 void ReleaseCurrentEvent();
244 int TriggerTCPSource( DataSource& source, bool useTimeout, unsigned long timeout );
245 int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout );
246 int ReadDataFromTCPSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
247 int ReadDataFromShmSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
248 int ParseSourceData( DataSource& source );
249 int ReAllocBlocks( unsigned long newCnt );
250 homer_uint64 GetSourceEventID( DataSource& source );
251 homer_uint64 GetSourceEventType( DataSource& source );
252 homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
254 homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
259 unsigned int fSource; // Index of originating data source
260 void* fData; // pointer to data
261 unsigned long fLength; // buffer length
262 homer_uint64* fMetaData; // Pointer to meta data describing data itself.
263 const char* fOriginatingNodeID; // node id from which the data originates
266 /** type of the current event */
267 homer_uint64 fCurrentEventType; //!transient
268 /** ID of the current event */
269 homer_uint64 fCurrentEventID; //!transient
270 /** no of blocks currently used */
271 unsigned long fBlockCnt; //!transient
272 /** available space in the block array */
273 unsigned long fMaxBlockCnt; //!transient
275 DataBlock* fBlocks; //!transient
277 /** total no of data sources */
278 unsigned int fDataSourceCnt; //!transient
279 /** no of TCP data sources */
280 unsigned int fTCPDataSourceCnt; //!transient
281 /** no of Shm data sources */
282 unsigned int fShmDataSourceCnt; //!transient
283 /** available space in the sources array */
284 unsigned int fDataSourceMaxCnt; //!transient
285 /** array of data source descriptions */
286 DataSource* fDataSources; //!transient
288 /** status of the connection */
289 int fConnectionStatus; //!transient
290 /** flag an error for */
291 unsigned fErrorConnection; //!transient
294 unsigned long fEventRequestAdvanceTime; //!transient
296 /** copy constructor prohibited */
297 HOMERReader(const HOMERReader&);
298 /** assignment operator prohibited */
299 HOMERReader& operator=(const HOMERReader&);
302 ClassDef(HOMERReader,2);
306 #endif /* AliHLTHOMERREADER_H */