]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERManager.cxx
deleting deprecated and uneffective defines
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
1 //-*- Mode: C++ -*-
2 // $Id$
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTHOMERManager.cxx
20     @author Jochen Thaeder
21     @date
22     @brief  Manger for HOMER in aliroot
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31 #define EVE_DEBUG 0
32
33 #include "AliHLTHOMERManager.h"
34 // -- -- -- -- -- -- -- 
35 #include "AliHLTHOMERLibManager.h"
36 #include "AliHLTHOMERSourceDesc.h"
37 #include "AliHLTHOMERBlockDesc.h"
38 // -- -- -- -- -- -- -- 
39 #include "AliHLTGlobalTriggerDecision.h"
40 #include "AliHLTTriggerDecision.h"
41 //---------------------------
42
43 using std::cout;
44
45 ClassImp(AliHLTHOMERManager)
46
47 /*
48  * ---------------------------------------------------------------------------------
49  *                            Constructor / Destructor
50  * ---------------------------------------------------------------------------------
51  */
52
53 //##################################################################################
54   AliHLTHOMERManager::AliHLTHOMERManager() :
55   fLibManager(new AliHLTHOMERLibManager),
56   fStateHasChanged(kTRUE),
57   fProxyHandler(NULL),
58   fCurrentReader(NULL),
59   fReaderList(NULL),
60   fSourceList(NULL),
61   fNBlks(0),
62   fEventID(),
63   fEventId(-1),
64   fCurrentBlk(0),
65   fAsyncBlockList(NULL),
66   fBlockList(NULL),
67    fEventBuffer(NULL),
68   fBufferTopIdx(-1),
69   fBufferLowIdx(-1),
70   fCurrentBufferIdx(-1),
71   fNavigateBufferIdx(-1),
72   fNEventsAvailable(0),
73   fConnected(kFALSE), 
74   fTriggerString("ALL"), 
75   fNEventsNotTriggered(0),
76   fRetryNextEvent(kFALSE),
77   fIsBlockOwner(kTRUE)
78 {
79   // see header file for class documentation
80   // or
81   // refer to README to build package
82   // or
83   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84
85 }
86
87 //##################################################################################
88 AliHLTHOMERManager::~AliHLTHOMERManager() {
89   // see header file for class documentation
90
91   if ( fLibManager ) {
92
93     if ( fReaderList ) {
94       TIter next(fReaderList);
95       TObject * object = NULL;
96       while ( ( object = next()) )
97         fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
98       
99       fReaderList->Clear();
100       delete fReaderList;
101     }
102     fReaderList = NULL;   
103     
104     delete fLibManager;
105   } 
106   fLibManager = NULL;
107
108   if ( fProxyHandler != NULL )
109     delete fProxyHandler;
110   fProxyHandler = NULL;
111
112   if ( fSourceList != NULL )
113     delete fSourceList;
114   fSourceList = NULL;
115
116   if ( fEventBuffer ) {
117     fEventBuffer->Clear();
118     delete fEventBuffer;
119   }
120   fEventBuffer = NULL;
121
122   if(fBlockList) {
123     fBlockList->Clear();
124     delete fBlockList;
125   }
126   fBlockList = NULL;
127
128   if ( fAsyncBlockList ) {
129     fAsyncBlockList->Delete();
130     delete fAsyncBlockList;
131   }
132   fAsyncBlockList = NULL;
133 }
134
135 //##################################################################################
136 Int_t AliHLTHOMERManager::Initialize() {
137   // see header file for class documentation
138
139   HLTInfo("Initializing");
140
141   Int_t iResult = 0;
142
143   // -- Initialize ProxyHandler
144   if ( !fProxyHandler )
145     fProxyHandler = new AliHLTHOMERProxyHandler();
146   
147   if ( fProxyHandler ) {
148     iResult = fProxyHandler->Initialize();
149     if (iResult)
150       HLTError("Initialize of ProxyHandler failed.");
151   
152   } else {
153     iResult = -1;
154     HLTError("Creating of ProxyHandler failed.");
155   }
156  
157   // -- Initialize ReaderList
158   //    List ist not owner, as reader have to be created/deleted by the LibManager
159   if( !fReaderList )
160     fReaderList = new TList();
161   
162   // -- Initialize asynchronous BlockList
163   if( !fAsyncBlockList ) {
164     fAsyncBlockList = new TList();
165     fAsyncBlockList->SetOwner(kTRUE);
166   }
167
168   //initialize normal block list
169   if( !fBlockList ) {
170     fBlockList = new TList();
171     fBlockList->SetOwner(kFALSE);
172   }
173
174   // -- Initialize Event Buffer and EventID array
175   if ( !fEventBuffer ) {
176     fEventBuffer = new TClonesArray( "TList", BUFFERSIZE );
177   }
178
179   for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) {
180     new ((*fEventBuffer)[idx]) TList( );
181     (reinterpret_cast<TList*>((*fEventBuffer)[idx]))->SetOwner(kTRUE);
182     
183     fEventID[idx] = 0;
184   }
185
186   return iResult;
187 }
188
189 /*
190  * ---------------------------------------------------------------------------------
191  *                                 Source Handling
192  * ---------------------------------------------------------------------------------
193  */
194
195 //##################################################################################
196 Int_t AliHLTHOMERManager::CreateSourcesList() {
197   // see header file for class documentation
198
199   if (fProxyHandler == NULL)
200   {
201     HLTError("The object must first be initialised with a call to Initialize().");
202     return -1;
203   }
204
205   Int_t iResult = 0;
206
207   if ( fSourceList != NULL )
208     delete fSourceList;
209   fSourceList = NULL;
210
211   fSourceList = new TList();
212   fSourceList->SetOwner( kTRUE );
213
214   iResult = fProxyHandler->FillSourceList( fSourceList );
215   if ( iResult < 0 ) {
216     HLTWarning("There have been errors, while creating the sources list.");
217   }
218   else if ( iResult > 0 ) {
219     HLTWarning("No active services found.");
220   }
221   else if ( fSourceList->IsEmpty() ) {
222     HLTWarning("No active services in the list.");
223     iResult = 2;
224   }
225   else {
226      HLTInfo("New sources list created.");
227
228     // -- New SourceList has been created 
229     // --> All Sources are new --> State has changed
230     fStateHasChanged = kTRUE;
231   }
232
233   return iResult;
234 }
235
236 //##################################################################################
237 void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) {
238   // see header file for class documentation
239
240   if ( source->IsSelected() != state ) {
241     source->SetState( state );
242     fStateHasChanged = kTRUE;
243   }
244
245   return;
246 }
247
248 /*
249  * ---------------------------------------------------------------------------------
250  *                         Connection Handling - public
251  * ---------------------------------------------------------------------------------
252  */
253
254 //##################################################################################
255 Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
256   // see header file for class documentation
257
258   if (fReaderList == NULL or fSourceList == NULL)
259   {
260     HLTError("Must first create a source list with a call to CreateSourcesList().");
261     return -1;
262   }
263   
264   Int_t iResult = 0;
265
266   // HAck Jochen
267   //----
268   detector="ALL";
269
270   // -- Check if LibManager is present
271   if ( ! fLibManager ) {
272     HLTError("No LibManager present.");
273     return -1;
274   }
275   
276   // -- Check if already connected and state has not changed
277   if ( fStateHasChanged == kFALSE && IsConnected() ) {
278     HLTInfo("No need for reconnection.");
279     return 0;
280   }
281   
282   // -- If already connected, disconnect before connect
283   //    or if ReaderList already filled
284   if ( IsConnected() || fReaderList->GetSize() != 0 ) {
285     HLTInfo(Form("IsConnected: %d      fReaderList.Size:   %d", IsConnected(), fReaderList->GetSize()));
286     DisconnectHOMER();
287   }
288   // -- Create the Readoutlist
289   UShort_t* sourcePorts = new UShort_t [fSourceList->GetEntries()];
290   const Char_t ** sourceHostnames = new const Char_t* [fSourceList->GetEntries()];
291   for(Int_t i = 0; i < fSourceList->GetEntries(); i++) {
292    sourceHostnames[i] = "";
293   }
294   UInt_t sourceCount = 0;
295
296   CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
297   if ( sourceCount == 0 ) {
298     HLTError("No sources selected, aborting.");
299     delete [] sourcePorts;
300     delete [] sourceHostnames;
301     return -2;
302   }
303
304   // ***
305   // *** Connect to data sources
306   // ***
307   
308   for (UInt_t idx = 0; idx < sourceCount; idx++) {
309     
310     if (sourcePorts[idx] > 60000)
311       continue;
312
313     HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx]));
314     
315     fReaderList->Add(dynamic_cast<TObject*>(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx])));
316     AliHLTHOMERReader *reader = static_cast<AliHLTHOMERReader*>(fReaderList->Last());
317     if ( !reader ) {
318       HLTError("Adding reader failed, aborting");
319       delete [] sourcePorts;
320       delete [] sourceHostnames;
321       return -3;
322     }
323
324     if ( (iResult = reader->GetConnectionStatus()) )  {
325
326       // -- Connection to source failed
327       
328       HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
329                     sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
330
331       if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) {
332         HLTInfo("The failed connection is on localhost. is SSH tunnel up????? ");
333         HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'",
334                      sourcePorts[idx], sourcePorts[idx]));
335       }
336       
337       // -- Remove reader
338       fReaderList->RemoveLast();
339
340       if ( reader )
341         fLibManager->DeleteReader( reader );
342       reader = NULL;
343       
344       HLTInfo(Form("Removed source %d,  %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx]));
345       
346     } 
347     else {
348       // -- Connection succeded
349       fConnected = kTRUE;
350
351       HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx]));
352     }
353     
354   } // for (Int_t idx = 0; idx < sourceCount; idx++) {
355   
356   delete[] sourceHostnames;
357   delete[] sourcePorts;
358
359   return iResult;
360
361 }
362
363 //##################################################################################
364 void AliHLTHOMERManager::DisconnectHOMER(){
365   // see header file for class documentation
366
367   HLTInfo("Disconnecting");
368
369   if ( fReaderList && fLibManager ) {
370     HLTInfo("Deleting readerlist and libmanager");
371     TIter next(fReaderList);
372     TObject * object = NULL;
373     while ( ( object = next()) ) 
374       fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
375       
376
377     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
378     fReaderList->Clear();
379     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
380     delete fReaderList;
381     fReaderList = new TList ();
382     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
383   }
384   
385   fStateHasChanged = kTRUE;
386   fConnected = kFALSE;
387   
388   HLTInfo("Connection closed.");
389
390   return;
391 }
392
393 //##################################################################################
394 Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
395   // see header file for class documentation
396   
397   Int_t iResult = 0;
398
399   if ( IsConnected() )
400     DisconnectHOMER();
401
402   iResult = ConnectHOMER(detector);
403   if ( iResult ) {
404     HLTError("Error reconnecting.");
405   }
406
407   return iResult;
408 }
409
410 /*
411  * ---------------------------------------------------------------------------------
412  *                            Event Handling - public
413  * ---------------------------------------------------------------------------------
414  */
415
416 //##################################################################################
417 Int_t AliHLTHOMERManager::NextEvent(){
418  
419   // see header file for class documentation
420   
421   Int_t iResult = 0;
422   Int_t iRetryCount = 0;
423   
424   if ( !IsConnected() || fStateHasChanged ) {
425     HLTInfo("Not connected or state has changed, returning to AliEveHOMERManager, which will deal with this situation");
426     //    cout << "connectecd  " << IsConnected()  << "haschanged  "<<fStateHasChanged << endl;
427     return 55;//ConnectHOMER();
428   }
429   if ( !IsConnected() ) {
430     HLTWarning("Not connected yet.");
431     return -1;
432   }
433
434   // -- Reset asyncronous BlockList
435   fAsyncBlockList->Delete();
436
437   // ***
438   // *** Loop over all readers and get new event data
439   // ***
440   
441   TIter next(fReaderList);
442   TObject * object = NULL;
443   
444   while( (object = next()) ) {
445     
446     fCurrentReader = static_cast<AliHLTHOMERReader*>(object);
447     
448     // -- Read next event data and error handling for HOMER (error codes and empty blocks)
449     while ( 1 ) {
450       
451       iResult = fCurrentReader->ReadNextEvent( 40000000 /*timeout in us*/);
452       
453       if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
454         HLTError(Form("No connection to source %d: %s (%d)", 
455                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
456         break;
457       } 
458       else if ( iResult == 110 ) {
459         HLTError(Form("Timeout occured, reading event from source %d: %s (%d)", 
460                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
461         break;
462       } 
463       else if ( iResult == 56 ) {
464         ++iRetryCount;
465       
466         if ( iRetryCount >= 20 ) {
467           HLTError(Form("Retry Failed: Error reading event from source %d: %s (%d), returning", 
468                         fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
469           break;
470         } 
471         else {
472           HLTError(Form("Retry: Error reading event from source %d: %s (%d), making another attempt (no %d out of 20)", 
473                         fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult, iRetryCount));
474           //break;
475           continue;
476         }
477       }
478       else if ( iResult ) {
479         HLTError(Form("General Error reading event from source %d: %s (%d), giving up", 
480                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
481         fConnected = kFALSE;
482         break;
483       } 
484       else {
485         HLTDebug("Successfully read out event from source");
486         break;
487       }
488
489     } // while( 1 ) {
490     
491     // -- Check if event could be read
492     if ( iResult ) {
493       HLTInfo("Reading event from source failed");
494       continue;
495     }
496
497     // -- Handle Blocks from current reader
498     iResult = HandleBlocks();
499     if ( iResult ) {
500       HLTError("Handling of blocks failed.");
501     }
502
503   } // while( (object = next()) ) {
504
505   return iResult;  
506 }
507
508 /* ---------------------------------------------------------------------------------
509  *                           Buffer Handling - public
510  * ---------------------------------------------------------------------------------
511  */
512
513 //##################################################################################
514 Int_t AliHLTHOMERManager::NavigateEventBufferBack() { 
515   // see header file for class documentation
516
517   // -- reached the end of the buffer
518   if ( fNavigateBufferIdx == fBufferLowIdx )
519     return -1;
520
521   Int_t newIdx = fNavigateBufferIdx - 1;
522   if ( newIdx == -1 )
523     newIdx = BUFFERSIZE-1;
524
525   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
526
527   return newIdx;
528 }
529
530 //##################################################################################
531 Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
532   // see header file for class documentation
533
534   HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
535
536   // -- reached the top of the buffer
537   if ( fNavigateBufferIdx == fBufferTopIdx )
538     return -1;
539
540   Int_t newIdx = fNavigateBufferIdx + 1;
541   if ( newIdx == BUFFERSIZE )
542     newIdx = 0;
543   
544   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
545   fNEventsAvailable -= 1;
546
547   HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
548
549
550   return 0;
551 }
552
553  ///////////////////////////////////////////////////////////////////////////////////
554
555 /*
556  * ---------------------------------------------------------------------------------
557  *                            Connection Handling - private
558  * ---------------------------------------------------------------------------------
559  */
560
561 //##################################################################################
562 void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts, 
563                                             UInt_t &sourceCount, TString detector ){
564   // see header file for class documentation
565
566   AliHLTHOMERSourceDesc * source= NULL;
567
568   // -- Read all sources and check if they should be read out
569   TIter next( fSourceList );
570   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
571
572     ///Don't use sources from dev cluster
573     if(source->GetPort() > 60000) continue;
574
575     // -- If detector NO detector name given
576     if ( ! detector.CompareTo("ALL") ) {
577       // -- Continue if source is not selected
578       // HACK Jochen
579       //if ( ! source->IsSelected() )
580       //        continue;
581     }
582     // -- DetectorName given
583     else {
584       // -- Continue if detector name doesn't match
585       if ( detector.CompareTo(source->GetDetector()) )
586         continue;
587       else
588         source->Select();
589     }
590     
591     Bool_t exists = kFALSE;
592     
593     // -- Loop over existing entries and check if entry is already in readout list
594     for ( UInt_t ii = 0; ii < sourceCount; ii++ ){
595       if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) 
596            && sourcePorts[ii] == source->GetPort() ) {
597         exists = kTRUE;
598         break;
599       }
600     }
601
602     // -- Add new entires to readout list
603     if ( ! exists ) {
604       sourcePorts[sourceCount] = source->GetPort();
605       sourceHostnames[sourceCount] = source->GetHostname().Data();
606       sourceCount++;
607     }
608
609   } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
610
611   fStateHasChanged = kFALSE;
612
613   return;
614 }
615
616 /*
617  * ---------------------------------------------------------------------------------
618  *                          Buffer Handling - private
619  * ---------------------------------------------------------------------------------
620  */
621
622 //##################################################################################
623 void AliHLTHOMERManager::AddBlockListToBuffer() {
624   // see header file for class documentation
625   // -- Check if event is already in buffer
626   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
627   
628   if ( fEventID[fBufferTopIdx] == eventID ) {
629     HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
630     return;
631   }
632
633   // -- Check if event should be selected on basis of trigger string
634   if( fTriggerString.CompareTo("ALL") ){
635     if ( !CheckTriggerDecision() ) {
636       HLTInfo("Event not triggered");
637       return;
638     } else {
639       HLTInfo("Event triggered");
640     }
641   }
642   else {
643     HLTDebug("No trigger selection.");
644   }
645
646   // -- Set Top mark 
647   ++fBufferTopIdx;
648   if ( fBufferTopIdx == BUFFERSIZE )
649     fBufferTopIdx = 0;
650
651   // -- Change the low mark if necessary
652   if ( fBufferLowIdx == -1 )
653     fBufferLowIdx = 0;
654   else if ( fBufferTopIdx == fBufferLowIdx ) {
655     ++fBufferLowIdx;
656     if ( fBufferLowIdx == BUFFERSIZE )
657       fBufferLowIdx = 0;
658   }
659
660
661   // -- Fill EventID
662   fEventID[fBufferTopIdx] = eventID;
663
664   // -- Clear Buffer slot
665   (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
666   if(fBlockList->IsOwner()) HLTWarning("block list is owner!!");
667   HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
668   //fBlockList->Clear();
669   fBlockList = new TList();
670   HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
671
672   GetFirstBlk();
673
674   // -- Fill block list
675   do {
676
677     // -- Create new block
678     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
679     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
680                      GetBlkType(), GetBlkSpecification() );
681     
682     // -- Check sources list if block is requested
683     if ( CheckIfRequested( block ) ) {
684       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
685       fBlockList->Add(block);
686     }
687     else {
688       // XXX HACK Jochen
689       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
690       fBlockList->Add(block);
691       // delete block;
692       // block = NULL;
693     }
694  
695   } while( GetNextBlk() );
696
697   //We have one more event available
698   fNEventsAvailable++;
699   HLTInfo(Form("fNEventsAvailable %d", fNEventsAvailable));
700   return;
701 }
702
703 //##################################################################################
704 void AliHLTHOMERManager::AddToAsyncBlockList() {
705   // see header file for class documentation
706
707   HLTInfo("Adding blocks to the asynchroneous block list");
708
709   GetFirstBlk();
710
711   do {
712     
713     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
714     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
715                      GetBlkType(), GetBlkSpecification() );
716     
717
718     fAsyncBlockList->Add( block );
719  
720   } while( GetNextBlk() );
721
722   return;
723 }
724 //__________________________________________________________________________________
725 void AliHLTHOMERManager::AddToBlockList() {
726   // see header file for class documentation
727   HLTInfo("Adding blocks to the synchroneous block list");
728
729   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
730   
731   if ( fEventId == eventID ) {
732     HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
733     return;
734   }
735
736   fEventId = eventID;
737
738   GetFirstBlk();
739   do {
740
741     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
742     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
743                      GetBlkType(), GetBlkSpecification() );
744     fBlockList->Add( block );
745   
746   } while( GetNextBlk() );  
747 }
748
749 //__________________________________________________________________________________
750 TList* AliHLTHOMERManager::GetBlockListEventBuffer() {
751   // see header file for class documentation
752
753   if(fBlockList)
754     return fBlockList;
755   else 
756     return NULL;
757
758
759 }
760
761
762 //__________________________________________________________________________________
763 Int_t AliHLTHOMERManager::HandleBlocks() {
764   // see header file for class documentation
765   
766   Int_t iResult = 0;
767
768   // -- Get blockCnt and eventID
769   fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt());
770   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
771   fCurrentBlk = 0;
772
773   // -- Check if blocks present
774   if ( fNBlks ==  0 ) {
775     HLTWarning(Form("Event 0x%016lX (%lu) with no blocks", eventID, eventID));
776     return -1;
777   }
778
779   HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks));
780     
781   if ( IsSyncBlocks() ) {
782     //AddBlockListToBuffer();
783     fBlockList->Clear();
784     AddToBlockList();
785   } else {
786     AddToAsyncBlockList();
787   }
788
789   return iResult;
790 }
791
792 //__________________________________________________________________________________
793 Bool_t AliHLTHOMERManager::IsSyncBlocks() {
794   // see header file for class documentation
795   
796   Bool_t bResult = kFALSE;
797
798   GetFirstBlk();
799   
800   do {          
801     
802     if ( !GetBlkType().CompareTo("ALIESDV0")) {
803       bResult = kTRUE;
804       break;
805     }
806
807     if ( !GetBlkType().CompareTo("GLOBTRIG")) {
808       bResult = kTRUE;
809       break;
810     }
811     
812     if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
813       AliHLTHOMERBlockDesc blockDesc;
814       
815       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
816                           GetBlkType(), GetBlkSpecification() );
817       if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
818
819         bResult = kTRUE;
820         break;
821       }
822     }
823
824   } while( GetNextBlk() );
825
826
827   return bResult;
828 }
829
830 //##################################################################################
831 void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
832   // see header file for class documentation
833   // Get pointer to current block in current event
834    
835   if ( !fCurrentReader || !IsConnected() ) {
836     HLTError("Not connected yet.");
837     return NULL;
838   }
839   if ( ndx < static_cast<Int_t>(fNBlks) )
840     return  const_cast<void*> (fCurrentReader->GetBlockData(ndx));
841   else
842     return NULL;
843 }
844
845 //##################################################################################
846 ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
847   // see header file for class documentation
848    
849   if ( !fCurrentReader || !IsConnected() ) {
850     HLTError("Not connected yet.");
851     return 0;
852   }
853   
854   if ( ndx < static_cast<Int_t>(fNBlks) )
855     return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx));
856   else
857     return 0;
858 }
859
860 //##################################################################################
861 TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
862   // see header file for class documentation
863
864   TString origin = "";
865
866   // -- Check for Connection
867   if ( !fCurrentReader || ! IsConnected() ) {
868     HLTError("Not connected yet.");
869     return origin;
870   }
871
872   // -- Check block index
873   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
874     HLTError(Form("Block index %d out of range.", ndx ));
875     return origin;
876   }
877
878   // -- Get origin
879   union{
880     UInt_t data;
881     Char_t array[4];
882   } reverseOrigin;
883
884   reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx));
885
886   // -- Reverse the order
887   for (Int_t ii = 3; ii >= 0; ii-- )
888     if ( reverseOrigin.array[ii] != ' ')
889       origin.Append( reverseOrigin.array[ii] );
890
891   origin.Remove( TString::kTrailing, ' ' );
892
893   return origin;
894 }
895
896 //##################################################################################
897 TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
898   // see header file for class documentation
899
900   TString type = "";
901
902   // -- Check for Connection
903   if ( !fCurrentReader || ! IsConnected() ) {
904     HLTError("Not connected yet.");
905     return type;
906   }
907
908   // -- Check block index
909   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
910     HLTError(Form("Block index %d out of range.", ndx ));
911     return type;
912   }
913
914   // -- Get type
915   union{
916     ULong64_t data;
917     Char_t array[8];
918   } reverseType;
919
920   reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx));
921
922   // -- Reverse the order
923   for (Int_t ii = 7; ii >= 0; ii-- )
924     if ( reverseType.array[ii] != ' ')
925       type.Append( reverseType.array[ii] );
926   
927   type.Remove( TString::kTrailing, ' ' );
928
929   return type;
930 }
931
932 //##################################################################################
933 ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
934   // see header file for class documentation
935
936   // -- Check for Connection
937   if ( !fCurrentReader || ! IsConnected() ) {
938     HLTError("Not connected yet.");
939     return 0;
940   }
941
942   // -- Check block index
943   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
944     HLTError(Form("Block index %d out of range.", ndx ));
945     return 0;
946   }
947
948   return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx));
949 }
950
951 //##################################################################################
952 Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
953   // see header file for class documentation
954
955   Bool_t requested = kFALSE;
956
957   AliHLTHOMERSourceDesc * source= NULL;
958
959   // -- Read all sources and check if they should be read out
960   TIter next( fSourceList );
961   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
962     
963     // -- Check if source is selected
964     if ( ! source->IsSelected() )
965       continue;
966     
967     // -- Check if detector matches
968     if ( source->GetSourceName().CompareTo( block->GetBlockName() ) )
969       continue;
970
971     requested = kTRUE;
972     break;
973
974   } // while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
975   
976 #if EVE_DEBUG
977   if ( requested ) {
978     HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); 
979   }
980   else {
981     HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data())); 
982   }
983 #endif
984
985   return requested;
986 }
987
988 /* ---------------------------------------------------------------------------------
989  *                          Trigger Handling - private
990  * ---------------------------------------------------------------------------------
991  */
992
993 //##################################################################################
994 Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
995   // see header file for class documentation
996
997   Bool_t triggered = kFALSE;
998
999   if ( !fCurrentReader || !IsConnected() ) {
1000     HLTError("Not connected yet.");
1001     return kFALSE;
1002   }
1003
1004   AliHLTHOMERBlockDesc blockDesc;
1005
1006   GetFirstBlk();
1007   
1008   // -- Fill block list
1009   Bool_t foundTriggerBlock = kFALSE;
1010   
1011   do {
1012     if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) {
1013       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
1014                           GetBlkType(), GetBlkSpecification() );
1015
1016       if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
1017
1018         foundTriggerBlock = kTRUE;
1019         break;
1020       }
1021       
1022     }
1023   } while( GetNextBlk() );
1024   
1025   if ( !foundTriggerBlock ) {
1026     HLTError("No trigger decision object found");
1027     return kFALSE;
1028   }
1029
1030   // -- Get the global decision object
1031   AliHLTGlobalTriggerDecision* globalDecision = 
1032     static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject());
1033
1034   if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) {
1035     triggered = globalDecision->EventTriggered();
1036   } 
1037   else {
1038     
1039     for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
1040        
1041       const AliHLTTriggerDecision* triggerDecision = 
1042         reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx));
1043     
1044       if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) {
1045         triggered = triggerDecision->EventTriggered();
1046         break;
1047       }
1048     } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
1049   }
1050
1051
1052
1053   if ( triggered ) {
1054     fRetryNextEvent = kFALSE;
1055     fNEventsNotTriggered = 0;
1056   }
1057   else {
1058     fRetryNextEvent = kTRUE;
1059     ++fNEventsNotTriggered;
1060   }
1061
1062   return triggered;
1063 }