]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/HOMER/AliHLTHOMERReader.h
coding conventions
[u/mrichter/AliRoot.git] / HLT / BASE / HOMER / AliHLTHOMERReader.h
CommitLineData
2be16a33 1// XEMacs -*-C++-*-
3a7c0444 2#ifndef AliHLTHOMERREADER_H
3#define AliHLTHOMERREADER_H
2be16a33 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 */
7
9e91e956 8/** @file AliHLTHOMERReader.h
2be16a33 9 @author Timm Steinbeck
10 @date Sep 14 2007
11 @brief HLT Online Monitoring Environment including ROOT - Reader
12 @note migrated from PubSub HLT-stable-20070905.141318 (rev 2375) */
13
14// see below for class documentation
15// or
16// refer to README to build package
17// or
18// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
19
20#include <limits.h>
21#include <sys/ipc.h>
22#include <sys/shm.h>
23#include "AliHLTHOMERData.h"
24
25
26
27
28class MonitoringReader
29 {
30 public:
31
32 MonitoringReader() {};
33 virtual ~MonitoringReader() {};
34
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;
39
40 /* Return the type of the current event */
41 virtual homer_uint64 GetEventType() const = 0;
42
43 /* Return the ID of the current event */
44 virtual homer_uint64 GetEventID() const = 0;
45
46 /* Return the number of data blocks in the current event */
47 virtual unsigned long GetBlockCnt() const = 0;
48
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
57 (starting at 0). */
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,
63 1 ist little endian,
64 2 is big endian. */
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
70 0: homer_uint64
71 1: homer_uint32
72 2: uin16
73 3: homer_uint8
74 4: double
75 5: float
76 */
77 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const = 0;
78
79 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const = 0;
80
81#ifdef USE_ROOT
82 ClassDef(MonitoringReader,1);
83#endif
84 };
85
86
87
88class HOMERReader: public MonitoringReader
89 {
90 public:
91#ifdef USE_ROOT
92 HOMERReader();
93#endif
94
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();
108
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
112 {
113 return fConnectionStatus;
114 }
115
116 /* Return the index of the connection for which an error given by the above
117 function occured. */
118 unsigned int GetErrorConnectionNdx() const
119 {
120 return fErrorConnection;
121 }
122
04a939f7 123 void SetEventRequestAdvanceTime( unsigned long time )
2be16a33 124 {
04a939f7 125 fEventRequestAdvanceTime = time;
2be16a33 126 }
127
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 );
133
134 /* Return the type of the current event */
135 virtual homer_uint64 GetEventType() const
136 {
137 return fCurrentEventType;
138 }
139
140 /* Return the ID of the current event */
141 virtual homer_uint64 GetEventID() const
142 {
143 return fCurrentEventID;
144 }
145
146 /* Return the number of data blocks in the current event */
147 virtual unsigned long GetBlockCnt() const
148 {
149 return fBlockCnt;
150 }
151
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
160 (starting at 0).
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,
168 1 ist little endian,
169 2 is big endian. */
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
175 0: homer_uint64
176 1: homer_uint32
177 2: uin16
178 3: homer_uint8
179 4: double
180 5: float
181 */
182 virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const;
183
184 virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
185
186 /* HOMER specific */
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;
196
197 /* Find the next data block in the current event with the given
198 data type, origin, and specification. Returns the block's
199 index. */
200 unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin,
201 homer_uint32 spec, unsigned long startNdx=0 ) const;
202
203 /* Find the next data block in the current event with the given
204 data type, origin, and specification. Returns the block's
205 index. */
206 unsigned long FindBlockNdx( char type[8], char origin[4],
207 homer_uint32 spec, unsigned long startNdx=0 ) const;
208
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;
213
214 protected:
215
216 enum DataSourceType { kUndef=0, kTCP, kShm };
217 struct DataSource
218 {
219 DataSource() { fType = kUndef; };
04a939f7 220 DataSourceType fType; // source type (TCP or Shm)
2be16a33 221 unsigned fNdx; // This source's index
222 const char* fHostname; // Filled for both Shm and TCP
04a939f7 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
2be16a33 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
232 };
233
234 void Init();
235
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 );
3a7c0444 252 homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
253
254 homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
2be16a33 255
256
257 struct DataBlock
258 {
259 unsigned int fSource; // Index of originating data source
04a939f7 260 void* fData; // pointer to data
261 unsigned long fLength; // buffer length
2be16a33 262 homer_uint64* fMetaData; // Pointer to meta data describing data itself.
04a939f7 263 const char* fOriginatingNodeID; // node id from which the data originates
2be16a33 264 };
265
04a939f7 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
274 /** block array */
275 DataBlock* fBlocks; //!transient
2be16a33 276
04a939f7 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
287
288 /** status of the connection */
289 int fConnectionStatus; //!transient
290 /** flag an error for */
291 unsigned fErrorConnection; //!transient
292
293 /** */
294 unsigned long fEventRequestAdvanceTime; //!transient
746d2a94 295 private:
296 /** copy constructor prohibited */
297 HOMERReader(const HOMERReader&);
298 /** assignment operator prohibited */
299 HOMERReader& operator=(const HOMERReader&);
2be16a33 300
301#ifdef USE_ROOT
302 ClassDef(HOMERReader,2);
303#endif
304 };
305
3a7c0444 306#endif /* AliHLTHOMERREADER_H */