]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERManager.h
changed back to unix style
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.h
1 //-*- Mode: C++ -*-
2
3 // $Id: AliHLTHOMERManager.h $
4
5 #ifndef ALIHLTHOMERMANAGER_H
6 #define ALIHLTHOMERMANAGER_H
7
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     
11  */
12
13 /** @file   AliHLTHOMERManager.h
14     @author Jochen Thaeder
15     @date
16     @brief  Manager for HOMER in aliroot
17 */
18
19
20 #include "TClonesArray.h"
21 #include "TString.h"
22 #include "TList.h"
23
24 #include "AliHLTHOMERSourceDesc.h"
25 #include "AliHLTHOMERBlockDesc.h"
26 #include "AliHLTHOMERReader.h"
27 #include "AliHLTHOMERProxyHandler.h"
28
29 #include "AliHLTLoggingVariadicFree.h"
30
31 #define BUFFERSIZE 100
32
33 class AliHLTHOMERLibManager;
34
35 /**
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.
42  * 
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.
46  *
47  * @ingroup alihlt_homer
48  */
49
50 class AliHLTHOMERManager : public AliHLTLogging 
51 {
52 public:
53   
54   /*
55    * ---------------------------------------------------------------------------------
56    *                            Constructor / Destructor
57    * ---------------------------------------------------------------------------------
58    */
59
60   /** default constructor */
61   AliHLTHOMERManager();
62
63   /** destructor */
64   virtual ~AliHLTHOMERManager();
65
66   /** Initialize 
67    *  @return 0 on success, <0 for failure
68    */
69   Int_t Initialize();
70
71   /*
72    * ---------------------------------------------------------------------------------
73    *                            Source Handling - public
74    * ---------------------------------------------------------------------------------
75    */
76
77   /** Create Sources List from HOMER-Proxy 
78    *  @return 0 on success, <0 for failure, 1 for no active service
79    */
80   virtual Int_t CreateSourcesList();
81
82   /** Set state of a source 
83    *  @param source      Pointer to AliHLTHOMERSourceDesc object.
84    *  @param state       New (selected/not selected) state.
85    */
86   void   SetSourceState( AliHLTHOMERSourceDesc* source, Bool_t state);
87
88   /** Get pointer to source List */
89   TList* GetSourceList() { return fSourceList; }
90
91   /*
92    * ---------------------------------------------------------------------------------
93    *                            Connection Handling - public
94    * ---------------------------------------------------------------------------------
95    */
96
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
101    */
102   Int_t ConnectHOMER( TString detector="ALL" );
103
104   /** Disconnect from HOMER sources */
105   void  DisconnectHOMER();
106
107   /** Reconnect from HOMER sources 
108    *  @param detector    Detector to be connected to
109    *  @return            0 on success, <0 for failure
110    */
111   Int_t ReconnectHOMER( TString detector);
112
113   /*
114    * ---------------------------------------------------------------------------------
115    *                            Event Handling - public
116    * ---------------------------------------------------------------------------------
117    */
118
119   /** Loads the next Event, after being connected 
120    *  @return 0 on success, <0 for failure
121    */
122   virtual Int_t NextEvent();
123
124   /** Loads the next Cycle, after being connected 
125    *  @return 0 on success, <0 for failure
126    */
127   virtual Int_t NextCycle() { return NextEvent(); }
128
129   /** Get event ID */
130   ULong_t GetEventID() { return fEventID[fCurrentBufferIdx]; }
131
132   /* ---------------------------------------------------------------------------------
133    *                           Buffer Handling - public
134    * ---------------------------------------------------------------------------------
135    */
136
137   /** Get pointer to last requested BlockList 
138    *  @return     ptr to buffer, NULL if buffer boundary reached                
139    */
140   TList* GetBlockList() { return GetBlockListEventBuffer(fCurrentBufferIdx); }
141
142   /** Get pointer to last asynchrounous BlockList 
143    *  @return     ptr to buffer, NULL if none present
144    */
145   TList* GetAsyncBlockList() { 
146     cout << "Returning asyncblocklist size : " <<
147       fAsyncBlockList->GetSize() << endl;
148     return fAsyncBlockList; 
149   }
150
151   /** Navigate backwards in event buffer 
152    *  @return      index in buffer, -1 if boundary reached                
153    */
154   Int_t  NavigateEventBufferBack();
155
156   /** Navigate forwards in event buffer 
157    *  @return      index in buffer, -1 if boundary reached                
158    */
159   Int_t  NavigateEventBufferFwd();
160
161   /* ---------------------------------------------------------------------------------
162    *                          Trigger Handling - public
163    * ---------------------------------------------------------------------------------
164    */
165
166   /** Set and get the string used to select triggers 
167    *  @param triggerString    Trigger selection string
168    */
169   void SetTriggerString ( TString triggerString ) { fTriggerString = triggerString; }
170
171   /** Get TriggerString */
172   TString GetTriggerString () { return fTriggerString; }
173
174   ///////////////////////////////////////////////////////////////////////////////////
175
176 protected:
177
178   /** Dynamic loader manager for the HOMER library */
179   AliHLTHOMERLibManager* fLibManager;             //! transient
180
181   /** Indicates, if a sources have changes, 
182    *  so that one has to reconnect. */
183   Bool_t    fStateHasChanged;                     //  see above
184
185   ///////////////////////////////////////////////////////////////////////////////////
186
187 private:
188
189   /** copy constructor prohibited */
190   AliHLTHOMERManager(const AliHLTHOMERManager&);
191
192   /** assignment operator prohibited */
193   AliHLTHOMERManager& operator=(const AliHLTHOMERManager&);
194
195   /*
196    * ---------------------------------------------------------------------------------
197    *                            Connection Handling - private
198    * ---------------------------------------------------------------------------------
199    */
200
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
206    */
207   void CreateReadoutList( const char** sourceHostnames, UShort_t* sourcePorts, 
208                           UInt_t &sourceCount, TString detector );
209
210   /** Checks if already connected to HOMER sources */
211   Bool_t IsConnected() { return fConnected; }  
212   
213   /* ---------------------------------------------------------------------------------
214    *                           Buffer Handling - private
215    * ---------------------------------------------------------------------------------
216    */
217
218   /** Create and add Block List to Buffer */
219   void AddBlockListToBuffer();
220
221   /** Add bocks to asynchronous BlockList */
222   void AddToAsyncBlockList();
223
224   /** Get pointer to block list in event buffer 
225    *  @return     ptr to buffer, NULL if not present
226    */
227   TList* GetBlockListEventBuffer( Int_t idx );
228     
229   /*
230    * ---------------------------------------------------------------------------------
231    *                            Block Handling - private
232    * ---------------------------------------------------------------------------------
233    */
234
235   /** Get Number of blocks in current event */
236   ULong_t GetNBlks() { return fNBlks; }
237
238   // ----------------------------------------------------
239
240   /** Handle Blocks and fill them in event buffer or asyncronous BlockList
241    *  @return 0 on success, <0 for failure
242    */
243   Int_t HandleBlocks();
244
245   /** Check is block are from syncronous source
246    *  @return kTRUE, if asyncronous kFALSE
247    */
248   Bool_t IsSyncBlocks();
249
250   // ----------------------------------------------------
251
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
255    */
256   void* GetBlk( Int_t ndx );
257
258   /** Get pointer to current block in current event */
259   void* GetBlk() { return GetBlk(fCurrentBlk); }
260
261   /** Get first block in current event */
262   void* GetFirstBlk() { fCurrentBlk=0; return GetBlk(0); }
263
264   /** Get next block in current event */
265   void* GetNextBlk() { return GetBlk(++fCurrentBlk); }
266
267   // ----------------------------------------------------
268
269   /** Get size of block ndx 
270    *  @param ndx        Block index
271    *  @return           returns size blk, 0 otherwise
272    */
273   ULong_t GetBlkSize( Int_t ndx );
274
275   /** Get size of current block */ 
276   ULong_t GetBlkSize() { return GetBlkSize( fCurrentBlk ); }
277
278   // ---------------------------------------------------- 
279
280   /** Get origin of block ndx 
281    *  @param ndx        Block index
282    *  @return           origin of block
283    */
284   TString GetBlkOrigin( Int_t ndx );
285
286   /** Get origin of current block */
287   TString GetBlkOrigin(){ return GetBlkOrigin( fCurrentBlk ); }
288
289   // ----------------------------------------------------
290
291   /** Get type of block ndx 
292    *  @param ndx        Block index
293    *  @return           type of block
294    */
295   TString GetBlkType( Int_t ndx ); 
296
297   /** Get type of current block */
298   TString GetBlkType() { return GetBlkType( fCurrentBlk ); } 
299   
300   // ----------------------------------------------------
301   
302   /** Get specification of block ndx 
303    *  @param ndx        Block index
304    *  @return           specification of block
305    */
306   ULong_t GetBlkSpecification( Int_t ndx );
307
308   /** Get specification of current block */
309   ULong_t GetBlkSpecification() { return GetBlkSpecification( fCurrentBlk ); } 
310
311   // ----------------------------------------------------
312
313   /** Checks if current Block should was requested 
314    *  @return           returns kTRUE, if block should was requested
315    */
316   Bool_t CheckIfRequested( AliHLTHOMERBlockDesc* block );
317
318   /* ---------------------------------------------------------------------------------
319    *                          Trigger Handling - private
320    * ---------------------------------------------------------------------------------
321    */
322   
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
327    */
328   Bool_t CheckTriggerDecision();
329
330   /*
331    * ---------------------------------------------------------------------------------
332    *                            Members - private
333    * ---------------------------------------------------------------------------------
334    */
335
336   /** Proxy Handler to get the list of sources */
337   AliHLTHOMERProxyHandler *fProxyHandler;               //! transient 
338
339   // == connection ==
340
341   /** Pointer to current HOMER reader */
342   AliHLTHOMERReader       *fCurrentReader;              //! transient 
343
344   /** List to pointer of HOMER readers */
345   TList                   *fReaderList;                 //! transient
346
347   // == sources ==
348
349   /** List to HOMER sources */
350   TList                   *fSourceList;                 //! transient
351
352   // == events ==
353
354   /** Number of blockes in current event */
355   ULong_t                  fNBlks;                      //  see above
356
357   /** EventID of current event */
358   ULong64_t                fEventID[BUFFERSIZE];        //  see above
359
360   /** Current block in current event */
361   ULong_t                  fCurrentBlk;                 //  see above
362
363   // == Asynchronous BlockList ==
364
365   /** List containing asychronous blocks */
366   TList                   *fAsyncBlockList;             //  see above
367
368   // == event buffer ==
369
370   /** Event Buffer */
371   TClonesArray            *fEventBuffer;                //  see above
372
373   /** Buffer index to last received event */
374   Int_t                    fBufferTopIdx;               //  see above
375
376   /** Buffer index to last received event */
377   Int_t                    fBufferLowIdx;               //  see above
378
379   /** Buffer index to current event */
380   Int_t                    fCurrentBufferIdx;           //  see above
381
382   /** Navigate index through event buffer */
383   Int_t                    fNavigateBufferIdx;          //  see above
384   
385   // == states ==
386   
387   /** Shows connection status */
388   Bool_t                   fConnected;                  //  see above
389
390   // == trigger selection ==
391
392   /** String indicating which trigger should be used to select events */
393   TString                  fTriggerString;              //  see above
394
395   /** Number Events not triggered, before next triggered event is found */
396   Int_t                    fNEventsNotTriggered;        //  see above
397
398   /** Retry reading next event */
399   Bool_t                   fRetryNextEvent;             //  see above
400
401   ClassDef(AliHLTHOMERManager, 1); // Manage connections to HLT data-sources.
402 };
403
404 #endif