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"
31 #define BUFFERSIZE 100
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() {
146 cout << "Returning asyncblocklist size : " <<
147 fAsyncBlockList->GetSize() << endl;
148 return fAsyncBlockList;
151 /** Navigate backwards in event buffer
152 * @return index in buffer, -1 if boundary reached
154 Int_t NavigateEventBufferBack();
156 /** Navigate forwards in event buffer
157 * @return index in buffer, -1 if boundary reached
159 Int_t NavigateEventBufferFwd();
161 /* ---------------------------------------------------------------------------------
162 * Trigger Handling - public
163 * ---------------------------------------------------------------------------------
166 /** Set and get the string used to select triggers
167 * @param triggerString Trigger selection string
169 void SetTriggerString ( TString triggerString ) { fTriggerString = triggerString; }
171 /** Get TriggerString */
172 TString GetTriggerString () { return fTriggerString; }
174 ///////////////////////////////////////////////////////////////////////////////////
178 /** Dynamic loader manager for the HOMER library */
179 AliHLTHOMERLibManager* fLibManager; //! transient
181 /** Indicates, if a sources have changes,
182 * so that one has to reconnect. */
183 Bool_t fStateHasChanged; // see above
185 ///////////////////////////////////////////////////////////////////////////////////
189 /** copy constructor prohibited */
190 AliHLTHOMERManager(const AliHLTHOMERManager&);
192 /** assignment operator prohibited */
193 AliHLTHOMERManager& operator=(const AliHLTHOMERManager&);
196 * ---------------------------------------------------------------------------------
197 * Connection Handling - private
198 * ---------------------------------------------------------------------------------
201 /** Create a readout list for Hostname and ports
202 * @param socurceHostnames Array of selected hostnames
203 * @param socurcePorts Array of selected ports
204 * @param socurceCount Number of selected hostname:port
205 * @param detector detector to be selected
207 void CreateReadoutList( const char** sourceHostnames, UShort_t* sourcePorts,
208 UInt_t &sourceCount, TString detector );
210 /** Checks if already connected to HOMER sources */
211 Bool_t IsConnected() { return fConnected; }
213 /* ---------------------------------------------------------------------------------
214 * Buffer Handling - private
215 * ---------------------------------------------------------------------------------
218 /** Create and add Block List to Buffer */
219 void AddBlockListToBuffer();
221 /** Add bocks to asynchronous BlockList */
222 void AddToAsyncBlockList();
224 /** Get pointer to block list in event buffer
225 * @return ptr to buffer, NULL if not present
227 TList* GetBlockListEventBuffer( Int_t idx );
230 * ---------------------------------------------------------------------------------
231 * Block Handling - private
232 * ---------------------------------------------------------------------------------
235 /** Get Number of blocks in current event */
236 ULong_t GetNBlks() { return fNBlks; }
238 // ----------------------------------------------------
240 /** Handle Blocks and fill them in event buffer or asyncronous BlockList
241 * @return 0 on success, <0 for failure
243 Int_t HandleBlocks();
245 /** Check is block are from syncronous source
246 * @return kTRUE, if asyncronous kFALSE
248 Bool_t IsSyncBlocks();
250 // ----------------------------------------------------
252 /** Get pointer to block ndx in current event
253 * @param ndx Block index
254 * @return returns pointer to blk, NULL if no block present
256 void* GetBlk( Int_t ndx );
258 /** Get pointer to current block in current event */
259 void* GetBlk() { return GetBlk(fCurrentBlk); }
261 /** Get first block in current event */
262 void* GetFirstBlk() { fCurrentBlk=0; return GetBlk(0); }
264 /** Get next block in current event */
265 void* GetNextBlk() { return GetBlk(++fCurrentBlk); }
267 // ----------------------------------------------------
269 /** Get size of block ndx
270 * @param ndx Block index
271 * @return returns size blk, 0 otherwise
273 ULong_t GetBlkSize( Int_t ndx );
275 /** Get size of current block */
276 ULong_t GetBlkSize() { return GetBlkSize( fCurrentBlk ); }
278 // ----------------------------------------------------
280 /** Get origin of block ndx
281 * @param ndx Block index
282 * @return origin of block
284 TString GetBlkOrigin( Int_t ndx );
286 /** Get origin of current block */
287 TString GetBlkOrigin(){ return GetBlkOrigin( fCurrentBlk ); }
289 // ----------------------------------------------------
291 /** Get type of block ndx
292 * @param ndx Block index
293 * @return type of block
295 TString GetBlkType( Int_t ndx );
297 /** Get type of current block */
298 TString GetBlkType() { return GetBlkType( fCurrentBlk ); }
300 // ----------------------------------------------------
302 /** Get specification of block ndx
303 * @param ndx Block index
304 * @return specification of block
306 ULong_t GetBlkSpecification( Int_t ndx );
308 /** Get specification of current block */
309 ULong_t GetBlkSpecification() { return GetBlkSpecification( fCurrentBlk ); }
311 // ----------------------------------------------------
313 /** Checks if current Block should was requested
314 * @return returns kTRUE, if block should was requested
316 Bool_t CheckIfRequested( AliHLTHOMERBlockDesc* block );
318 /* ---------------------------------------------------------------------------------
319 * Trigger Handling - private
320 * ---------------------------------------------------------------------------------
323 /** Loops over the data block from all the readers in the readerlist until
324 * a triggerdecsision has been found
325 * Locates the triggerdecision required by fTriggerString and checks if it triggered
326 * @return returns kTRUE, if event was triggered, kFALSE otherwise
328 Bool_t CheckTriggerDecision();
331 * ---------------------------------------------------------------------------------
333 * ---------------------------------------------------------------------------------
336 /** Proxy Handler to get the list of sources */
337 AliHLTHOMERProxyHandler *fProxyHandler; //! transient
341 /** Pointer to current HOMER reader */
342 AliHLTHOMERReader *fCurrentReader; //! transient
344 /** List to pointer of HOMER readers */
345 TList *fReaderList; //! transient
349 /** List to HOMER sources */
350 TList *fSourceList; //! transient
354 /** Number of blockes in current event */
355 ULong_t fNBlks; // see above
357 /** EventID of current event */
358 ULong64_t fEventID[BUFFERSIZE]; // see above
360 /** Current block in current event */
361 ULong_t fCurrentBlk; // see above
363 // == Asynchronous BlockList ==
365 /** List containing asychronous blocks */
366 TList *fAsyncBlockList; // see above
368 // == event buffer ==
371 TClonesArray *fEventBuffer; // see above
373 /** Buffer index to last received event */
374 Int_t fBufferTopIdx; // see above
376 /** Buffer index to last received event */
377 Int_t fBufferLowIdx; // see above
379 /** Buffer index to current event */
380 Int_t fCurrentBufferIdx; // see above
382 /** Navigate index through event buffer */
383 Int_t fNavigateBufferIdx; // see above
387 /** Shows connection status */
388 Bool_t fConnected; // see above
390 // == trigger selection ==
392 /** String indicating which trigger should be used to select events */
393 TString fTriggerString; // see above
395 /** Number Events not triggered, before next triggered event is found */
396 Int_t fNEventsNotTriggered; // see above
398 /** Retry reading next event */
399 Bool_t fRetryNextEvent; // see above
401 ClassDef(AliHLTHOMERManager, 1); // Manage connections to HLT data-sources.