]>
Commit | Line | Data |
---|---|---|
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 | ||
fe1edbae | 28 | class AliHLTMonitoringReader |
2be16a33 | 29 | { |
30 | public: | |
31 | ||
fe1edbae | 32 | AliHLTMonitoringReader() {}; |
33 | virtual ~AliHLTMonitoringReader() {}; | |
2be16a33 | 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 | |
fe1edbae | 82 | ClassDef(AliHLTMonitoringReader,1); |
2be16a33 | 83 | #endif |
84 | }; | |
85 | ||
86 | ||
87 | ||
fe1edbae | 88 | class AliHLTHOMERReader: public AliHLTMonitoringReader |
2be16a33 | 89 | { |
90 | public: | |
91 | #ifdef USE_ROOT | |
fe1edbae | 92 | AliHLTHOMERReader(); |
2be16a33 | 93 | #endif |
94 | ||
95 | /* Constructors & destructors, HOMER specific */ | |
96 | /* For reading from a TCP port */ | |
fe1edbae | 97 | AliHLTHOMERReader( const char* hostname, unsigned short port ); |
2be16a33 | 98 | /* For reading from multiple TCP ports */ |
fe1edbae | 99 | AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports ); |
2be16a33 | 100 | /* For reading from a System V shared memory segment */ |
fe1edbae | 101 | AliHLTHOMERReader( key_t shmKey, int shmSize ); |
2be16a33 | 102 | /* For reading from multiple System V shared memory segments */ |
fe1edbae | 103 | AliHLTHOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize ); |
2be16a33 | 104 | /* For reading from multiple TCP ports and multiple System V shared memory segments */ |
fe1edbae | 105 | AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports, |
2be16a33 | 106 | unsigned int shmCnt, key_t* shmKey, int* shmSize ); |
fe1edbae | 107 | virtual ~AliHLTHOMERReader(); |
2be16a33 | 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 | { |
1d47dbac | 125 | // advance time in us |
04a939f7 | 126 | fEventRequestAdvanceTime = time; |
2be16a33 | 127 | } |
128 | ||
fe1edbae | 129 | /* Defined in AliHLTMonitoringReader */ |
2be16a33 | 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 ); | |
134 | ||
135 | /* Return the type of the current event */ | |
136 | virtual homer_uint64 GetEventType() const | |
137 | { | |
138 | return fCurrentEventType; | |
139 | } | |
140 | ||
141 | /* Return the ID of the current event */ | |
142 | virtual homer_uint64 GetEventID() const | |
143 | { | |
144 | return fCurrentEventID; | |
145 | } | |
146 | ||
147 | /* Return the number of data blocks in the current event */ | |
148 | virtual unsigned long GetBlockCnt() const | |
149 | { | |
150 | return fBlockCnt; | |
151 | } | |
152 | ||
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 | |
161 | (starting at 0). | |
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, | |
169 | 1 ist little endian, | |
170 | 2 is big endian. */ | |
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 | |
176 | 0: homer_uint64 | |
177 | 1: homer_uint32 | |
178 | 2: uin16 | |
179 | 3: homer_uint8 | |
180 | 4: double | |
181 | 5: float | |
182 | */ | |
183 | virtual homer_uint8 GetBlockTypeAlignment( unsigned long ndx, homer_uint8 dataType ) const; | |
184 | ||
185 | virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const; | |
186 | ||
187 | /* HOMER specific */ | |
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; | |
197 | ||
198 | /* Find the next data block in the current event with the given | |
199 | data type, origin, and specification. Returns the block's | |
200 | index. */ | |
201 | unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin, | |
202 | homer_uint32 spec, unsigned long startNdx=0 ) const; | |
203 | ||
204 | /* Find the next data block in the current event with the given | |
205 | data type, origin, and specification. Returns the block's | |
206 | index. */ | |
207 | unsigned long FindBlockNdx( char type[8], char origin[4], | |
208 | homer_uint32 spec, unsigned long startNdx=0 ) const; | |
209 | ||
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; | |
214 | ||
215 | protected: | |
216 | ||
217 | enum DataSourceType { kUndef=0, kTCP, kShm }; | |
218 | struct DataSource | |
219 | { | |
220 | DataSource() { fType = kUndef; }; | |
04a939f7 | 221 | DataSourceType fType; // source type (TCP or Shm) |
2be16a33 | 222 | unsigned fNdx; // This source's index |
223 | const char* fHostname; // Filled for both Shm and TCP | |
04a939f7 | 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 | |
2be16a33 | 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 | |
233 | }; | |
234 | ||
235 | void Init(); | |
236 | ||
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 ); | |
3a7c0444 | 253 | homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const; |
254 | ||
255 | homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const; | |
2be16a33 | 256 | |
257 | ||
258 | struct DataBlock | |
259 | { | |
260 | unsigned int fSource; // Index of originating data source | |
04a939f7 | 261 | void* fData; // pointer to data |
262 | unsigned long fLength; // buffer length | |
2be16a33 | 263 | homer_uint64* fMetaData; // Pointer to meta data describing data itself. |
04a939f7 | 264 | const char* fOriginatingNodeID; // node id from which the data originates |
2be16a33 | 265 | }; |
266 | ||
1d47dbac | 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 | |
275 | /** block array */ | |
276 | DataBlock* fBlocks; //!transient | |
277 | ||
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 | |
288 | ||
289 | /** status of the connection */ | |
290 | int fConnectionStatus; //!transient | |
291 | /** flag an error for */ | |
292 | unsigned fErrorConnection; //!transient | |
293 | ||
294 | /** */ | |
295 | unsigned long fEventRequestAdvanceTime; //!transient | |
746d2a94 | 296 | private: |
1d47dbac | 297 | /** copy constructor prohibited */ |
fe1edbae | 298 | AliHLTHOMERReader(const AliHLTHOMERReader&); |
1d47dbac | 299 | /** assignment operator prohibited */ |
fe1edbae | 300 | AliHLTHOMERReader& operator=(const AliHLTHOMERReader&); |
1d47dbac | 301 | |
2be16a33 | 302 | #ifdef USE_ROOT |
fe1edbae | 303 | ClassDef(AliHLTHOMERReader,2); |
2be16a33 | 304 | #endif |
305 | }; | |
306 | ||
fe1edbae | 307 | /** defined for backward compatibility */ |
308 | typedef AliHLTMonitoringReader MonitoringReader; | |
309 | /** defined for backward compatibility */ | |
310 | typedef AliHLTHOMERReader HOMERReader; | |
311 | ||
312 | // external interface of the HOMER reader | |
313 | #define ALIHLTHOMERREADER_CREATE_FROM_BUFFER "AliHLTHOMERReaderCreateFromBuffer" | |
314 | #define ALIHLTHOMERREADER_DELETE "AliHLTHOMERReaderDelete" | |
315 | ||
316 | #ifdef __cplusplus | |
317 | extern "C" { | |
318 | #endif | |
319 | ||
320 | typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromBuffer_t)(const void* pBuffer, int size); | |
321 | typedef void (*AliHLTHOMERReaderDelete_t)(AliHLTHOMERReader* pInstance); | |
322 | /** | |
323 | * Create instance of HOMER reader. | |
324 | */ | |
325 | AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer(); | |
326 | ||
327 | /** | |
328 | * Delete instance of HOMER reader. | |
329 | */ | |
330 | void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance); | |
331 | #ifdef __cplusplus | |
332 | } | |
333 | #endif | |
334 | ||
3a7c0444 | 335 | #endif /* AliHLTHOMERREADER_H */ |