3 // $Id: AliHLTHOMERManager.h $
5 #ifndef ALIHLTHOMERMANAGER_H
6 #define ALIHLTHOMERMANAGER_H
8 /* This file is property of and copyright by the ALICE HLT Project *
9 * ALICE Experiment at CERN, All rights reserved. *
10 * See cxx source for full Copyright notice
13 /** @file AliHLTHOMERManager.h
14 @author Jochen Thaeder
16 @brief Manager for HOMER in aliroot
20 #include "TClonesArray.h"
24 #include "AliHLTHOMERSourceDesc.h"
25 #include "AliHLTHOMERBlockDesc.h"
26 #include "AliHLTHOMERReader.h"
27 #include "AliHLTHOMERProxyHandler.h"
29 #include "AliHLTLoggingVariadicFree.h"
33 class AliHLTHOMERLibManager;
36 * @class AliHLTHOMERManager
37 * This Class should handle the communication
38 * from the HLT to aliroot. The HLT sends data via
39 * the HOMER interface on several TCP ports of nodes
40 * in the CERN GPN and DCS network.
41 * All this communication is hidden from the user.
43 * Right now, a xml file ( SCC1 ) is used to get the
44 * configuration, this will/ has to change to a proxy
45 * running on dedicated nodes.
47 * @ingroup alihlt_homer
50 class AliHLTHOMERManager : public AliHLTLogging
55 * ---------------------------------------------------------------------------------
56 * Constructor / Destructor
57 * ---------------------------------------------------------------------------------
60 /** default constructor */
64 virtual ~AliHLTHOMERManager();
67 * @return 0 on success, <0 for failure
72 * ---------------------------------------------------------------------------------
73 * Source Handling - public
74 * ---------------------------------------------------------------------------------
77 /** Create Sources List from HOMER-Proxy
78 * @return 0 on success, <0 for failure, 1 for no active service
80 virtual Int_t CreateSourcesList();
82 /** Set state of a source
83 * @param source Pointer to AliHLTHOMERSourceDesc object.
84 * @param state New (selected/not selected) state.
86 void SetSourceState( AliHLTHOMERSourceDesc* source, Bool_t state);
88 /** Get pointer to source List */
89 TList* GetSourceList() { return fSourceList; }
92 * ---------------------------------------------------------------------------------
93 * Connection Handling - public
94 * ---------------------------------------------------------------------------------
97 /** Connect to HOMER sources, of a certain detector.
98 * which gets created when state has changed
99 * @param detector Detector to be connected to
100 * @return 0 on success, <0 for failure
102 Int_t ConnectHOMER( TString detector="ALL" );
104 /** Disconnect from HOMER sources */
105 void DisconnectHOMER();
107 /** Reconnect from HOMER sources
108 * @param detector Detector to be connected to
109 * @return 0 on success, <0 for failure
111 Int_t ReconnectHOMER( TString detector);
114 * ---------------------------------------------------------------------------------
115 * Event Handling - public
116 * ---------------------------------------------------------------------------------
119 /** Loads the next Event, after being connected
120 * @return 0 on success, <0 for failure
122 virtual Int_t NextEvent();
124 /** Loads the next Cycle, after being connected
125 * @return 0 on success, <0 for failure
127 virtual Int_t NextCycle() { return NextEvent(); }
130 ULong_t GetEventID() { return fEventID[fCurrentBufferIdx]; }
132 /* ---------------------------------------------------------------------------------
133 * Buffer Handling - public
134 * ---------------------------------------------------------------------------------
137 /** Get pointer to last requested BlockList
138 * @return ptr to buffer, NULL if buffer boundary reached
140 TList* GetBlockList() { return GetBlockListEventBuffer(fCurrentBufferIdx); }
142 /** Get pointer to last asynchrounous BlockList
143 * @return ptr to buffer, NULL if none present
145 TList* GetAsyncBlockList() { return fAsyncBlockList; }
147 /** Navigate backwards in event buffer
148 * @return index in buffer, -1 if boundary reached
150 Int_t NavigateEventBufferBack();
152 /** Navigate forwards in event buffer
153 * @return index in buffer, -1 if boundary reached
155 Int_t NavigateEventBufferFwd();
157 /* ---------------------------------------------------------------------------------
158 * Trigger Handling - public
159 * ---------------------------------------------------------------------------------
162 /** Set and get the string used to select triggers
163 * @param triggerString Trigger selection string
165 void SetTriggerString ( TString triggerString ) { fTriggerString = triggerString; }
167 /** Get TriggerString */
168 TString GetTriggerString () { return fTriggerString; }
170 ///////////////////////////////////////////////////////////////////////////////////
174 /** Dynamic loader manager for the HOMER library */
175 AliHLTHOMERLibManager* fLibManager; //! transient
177 /** Indicates, if a sources have changes,
178 * so that one has to reconnect. */
179 Bool_t fStateHasChanged; // see above
181 ///////////////////////////////////////////////////////////////////////////////////
185 /** copy constructor prohibited */
186 AliHLTHOMERManager(const AliHLTHOMERManager&);
188 /** assignment operator prohibited */
189 AliHLTHOMERManager& operator=(const AliHLTHOMERManager&);
192 * ---------------------------------------------------------------------------------
193 * Connection Handling - private
194 * ---------------------------------------------------------------------------------
197 /** Create a readout list for Hostname and ports
198 * @param socurceHostnames Array of selected hostnames
199 * @param socurcePorts Array of selected ports
200 * @param socurceCount Number of selected hostname:port
201 * @param detector detector to be selected
203 void CreateReadoutList( const char** sourceHostnames, UShort_t* sourcePorts,
204 UInt_t &sourceCount, TString detector );
206 /** Checks if already connected to HOMER sources */
207 Bool_t IsConnected() { return fConnected; }
209 /* ---------------------------------------------------------------------------------
210 * Buffer Handling - private
211 * ---------------------------------------------------------------------------------
214 /** Create and add Block List to Buffer */
215 void AddBlockListToBuffer();
217 /** Add bocks to asynchronous BlockList */
218 void AddToAsyncBlockList();
220 /** Get pointer to block list in event buffer
221 * @return ptr to buffer, NULL if not present
223 TList* GetBlockListEventBuffer( Int_t idx );
226 * ---------------------------------------------------------------------------------
227 * Block Handling - private
228 * ---------------------------------------------------------------------------------
231 /** Get Number of blocks in current event */
232 ULong_t GetNBlks() { return fNBlks; }
234 // ----------------------------------------------------
236 /** Handle Blocks and fill them in event buffer or asyncronous BlockList
237 * @return 0 on success, <0 for failure
239 Int_t HandleBlocks();
241 /** Check is block are from syncronous source
242 * @return kTRUE, if asyncronous kFALSE
244 Bool_t IsSyncBlocks();
246 // ----------------------------------------------------
248 /** Get pointer to block ndx in current event
249 * @param ndx Block index
250 * @return returns pointer to blk, NULL if no block present
252 void* GetBlk( Int_t ndx );
254 /** Get pointer to current block in current event */
255 void* GetBlk() { return GetBlk(fCurrentBlk); }
257 /** Get first block in current event */
258 void* GetFirstBlk() { fCurrentBlk=0; return GetBlk(0); }
260 /** Get next block in current event */
261 void* GetNextBlk() { return GetBlk(++fCurrentBlk); }
263 // ----------------------------------------------------
265 /** Get size of block ndx
266 * @param ndx Block index
267 * @return returns size blk, 0 otherwise
269 ULong_t GetBlkSize( Int_t ndx );
271 /** Get size of current block */
272 ULong_t GetBlkSize() { return GetBlkSize( fCurrentBlk ); }
274 // ----------------------------------------------------
276 /** Get origin of block ndx
277 * @param ndx Block index
278 * @return origin of block
280 TString GetBlkOrigin( Int_t ndx );
282 /** Get origin of current block */
283 TString GetBlkOrigin(){ return GetBlkOrigin( fCurrentBlk ); }
285 // ----------------------------------------------------
287 /** Get type of block ndx
288 * @param ndx Block index
289 * @return type of block
291 TString GetBlkType( Int_t ndx );
293 /** Get type of current block */
294 TString GetBlkType() { return GetBlkType( fCurrentBlk ); }
296 // ----------------------------------------------------
298 /** Get specification of block ndx
299 * @param ndx Block index
300 * @return specification of block
302 ULong_t GetBlkSpecification( Int_t ndx );
304 /** Get specification of current block */
305 ULong_t GetBlkSpecification() { return GetBlkSpecification( fCurrentBlk ); }
307 // ----------------------------------------------------
309 /** Checks if current Block should was requested
310 * @return returns kTRUE, if block should was requested
312 Bool_t CheckIfRequested( AliHLTHOMERBlockDesc* block );
314 /* ---------------------------------------------------------------------------------
315 * Trigger Handling - private
316 * ---------------------------------------------------------------------------------
319 /** Loops over the data block from all the readers in the readerlist until
320 * a triggerdecsision has been found
321 * Locates the triggerdecision required by fTriggerString and checks if it triggered
322 * @return returns kTRUE, if event was triggered, kFALSE otherwise
324 Bool_t CheckTriggerDecision();
327 * ---------------------------------------------------------------------------------
329 * ---------------------------------------------------------------------------------
332 /** Proxy Handler to get the list of sources */
333 AliHLTHOMERProxyHandler *fProxyHandler; //! transient
337 /** Pointer to current HOMER reader */
338 AliHLTHOMERReader *fCurrentReader; //! transient
340 /** List to pointer of HOMER readers */
341 TList *fReaderList; //! transient
345 /** List to HOMER sources */
346 TList *fSourceList; //! transient
350 /** Number of blockes in current event */
351 ULong_t fNBlks; // see above
353 /** EventID of current event */
354 ULong64_t fEventID[BUFFERSIZE]; // see above
356 /** Current block in current event */
357 ULong_t fCurrentBlk; // see above
359 // == Asynchronous BlockList ==
361 /** List containing asychronous blocks */
362 TList *fAsyncBlockList; // see above
364 // == event buffer ==
367 TClonesArray *fEventBuffer; // see above
369 /** Buffer index to last received event */
370 Int_t fBufferTopIdx; // see above
372 /** Buffer index to last received event */
373 Int_t fBufferLowIdx; // see above
375 /** Buffer index to current event */
376 Int_t fCurrentBufferIdx; // see above
378 /** Navigate index through event buffer */
379 Int_t fNavigateBufferIdx; // see above
383 /** Shows connection status */
384 Bool_t fConnected; // see above
386 // == trigger selection ==
388 /** String indicating which trigger should be used to select events */
389 TString fTriggerString; // see above
391 /** Number Events not triggered, before next triggered event is found */
392 Int_t fNEventsNotTriggered; // see above
394 /** Retry reading next event */
395 Bool_t fRetryNextEvent; // see above
397 ClassDef(AliHLTHOMERManager, 1); // Manage connections to HLT data-sources.