]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTHOMERManager.cxx
CMake: removing qpythia from the depedencies
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
index 2234e86c332ec95c41b0e88ea04018b64d9188ce..d045b02be9d3b656cfe364f6422646e4ffbf942e 100644 (file)
@@ -1,5 +1,5 @@
 //-*- Mode: C++ -*-
-// $Id: AliHLTHOMERManager.cxx  $
+// $Id$
 //**************************************************************************
 //* This file is property of and copyright by the ALICE HLT Project        * 
 //* ALICE Experiment at CERN, All rights reserved.                         *
 // or
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
-#if __GNUC__>= 3
-   using namespace std;
-#endif
-
 #define EVE_DEBUG 0
 
 #include "AliHLTHOMERManager.h"
 #include "AliHLTHOMERSourceDesc.h"
 #include "AliHLTHOMERBlockDesc.h"
 // -- -- -- -- -- -- -- 
+#include "AliHLTGlobalTriggerDecision.h"
+#include "AliHLTTriggerDecision.h"
+//---------------------------
+
+using std::cout;
+
 ClassImp(AliHLTHOMERManager)
 
 /*
@@ -53,13 +55,27 @@ ClassImp(AliHLTHOMERManager)
   fLibManager(new AliHLTHOMERLibManager),
   fStateHasChanged(kTRUE),
   fProxyHandler(NULL),
-  fReader(NULL),
+  fCurrentReader(NULL),
+  fReaderList(NULL),
   fSourceList(NULL),
-  fBlockList(NULL),
   fNBlks(0),
-  fEventID(0),
+  fEventID(),
+  fEventId(-1),
   fCurrentBlk(0),
-  fConnected(kFALSE) {
+  fAsyncBlockList(NULL),
+  fBlockList(NULL),
+   fEventBuffer(NULL),
+  fBufferTopIdx(-1),
+  fBufferLowIdx(-1),
+  fCurrentBufferIdx(-1),
+  fNavigateBufferIdx(-1),
+  fNEventsAvailable(0),
+  fConnected(kFALSE), 
+  fTriggerString("ALL"), 
+  fNEventsNotTriggered(0),
+  fRetryNextEvent(kFALSE),
+  fIsBlockOwner(kTRUE)
+{
   // see header file for class documentation
   // or
   // refer to README to build package
@@ -73,12 +89,21 @@ AliHLTHOMERManager::~AliHLTHOMERManager() {
   // see header file for class documentation
 
   if ( fLibManager ) {
-    if ( fReader )
-      fLibManager->DeleteReader(fReader);
+
+    if ( fReaderList ) {
+      TIter next(fReaderList);
+      TObject * object = NULL;
+      while ( ( object = next()) )
+       fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
+      
+      fReaderList->Clear();
+      delete fReaderList;
+    }
+    fReaderList = NULL;   
+    
     delete fLibManager;
-    fLibManager = NULL;
-    fReader = NULL;
-  }
+  } 
+  fLibManager = NULL;
 
   if ( fProxyHandler != NULL )
     delete fProxyHandler;
@@ -88,30 +113,76 @@ AliHLTHOMERManager::~AliHLTHOMERManager() {
     delete fSourceList;
   fSourceList = NULL;
 
-  if ( fBlockList != NULL )
+  if ( fEventBuffer ) {
+    fEventBuffer->Clear();
+    delete fEventBuffer;
+  }
+  fEventBuffer = NULL;
+
+  if(fBlockList) {
+    fBlockList->Clear();
     delete fBlockList;
+  }
   fBlockList = NULL;
+
+  if ( fAsyncBlockList ) {
+    fAsyncBlockList->Delete();
+    delete fAsyncBlockList;
+  }
+  fAsyncBlockList = NULL;
 }
 
 //##################################################################################
 Int_t AliHLTHOMERManager::Initialize() {
   // see header file for class documentation
 
+  HLTInfo("Initializing");
+
   Int_t iResult = 0;
 
+  // -- Initialize ProxyHandler
   if ( !fProxyHandler )
     fProxyHandler = new AliHLTHOMERProxyHandler();
   
   if ( fProxyHandler ) {
     iResult = fProxyHandler->Initialize();
     if (iResult)
-      HLTError(Form("Initialize of ProxyHandler failed."));
-  }
-  else {
+      HLTError("Initialize of ProxyHandler failed.");
+  
+  else {
     iResult = -1;
-    HLTError(Form("Creating of ProxyHandler failed."));
+    HLTError("Creating of ProxyHandler failed.");
   }
  
+  // -- Initialize ReaderList
+  //    List ist not owner, as reader have to be created/deleted by the LibManager
+  if( !fReaderList )
+    fReaderList = new TList();
+  
+  // -- Initialize asynchronous BlockList
+  if( !fAsyncBlockList ) {
+    fAsyncBlockList = new TList();
+    fAsyncBlockList->SetOwner(kTRUE);
+  }
+
+  //initialize normal block list
+  if( !fBlockList ) {
+    fBlockList = new TList();
+    fBlockList->SetOwner(kFALSE);
+  }
+
+  // -- Initialize Event Buffer and EventID array
+  if ( !fEventBuffer ) {
+    fEventBuffer = new TClonesArray( "TList", BUFFERSIZE );
+  }
+
+  for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) {
+    new ((*fEventBuffer)[idx]) TList( );
+    (reinterpret_cast<TList*>((*fEventBuffer)[idx]))->SetOwner(kTRUE);
+    
+    fEventID[idx] = 0;
+  }
+
   return iResult;
 }
 
@@ -125,8 +196,14 @@ Int_t AliHLTHOMERManager::Initialize() {
 Int_t AliHLTHOMERManager::CreateSourcesList() {
   // see header file for class documentation
 
+  if (fProxyHandler == NULL)
+  {
+    HLTError("The object must first be initialised with a call to Initialize().");
+    return -1;
+  }
+
   Int_t iResult = 0;
-  
+
   if ( fSourceList != NULL )
     delete fSourceList;
   fSourceList = NULL;
@@ -136,17 +213,17 @@ Int_t AliHLTHOMERManager::CreateSourcesList() {
 
   iResult = fProxyHandler->FillSourceList( fSourceList );
   if ( iResult < 0 ) {
-    HLTWarning(Form("There have been errors, while creating the sources list."));
+    HLTWarning("There have been errors, while creating the sources list.");
   }
   else if ( iResult > 0 ) {
-    HLTWarning(Form("No active services found."));
+    HLTWarning("No active services found.");
   }
   else if ( fSourceList->IsEmpty() ) {
-    HLTWarning(Form("No active services in the list."));
+    HLTWarning("No active services in the list.");
     iResult = 2;
   }
   else {
-     HLTInfo(Form("New sources list created."));
+     HLTInfo("New sources list created.");
 
     // -- New SourceList has been created 
     // --> All Sources are new --> State has changed
@@ -170,7 +247,7 @@ void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t
 
 /*
  * ---------------------------------------------------------------------------------
- *                         Connection Handling -oublic
+ *                         Connection Handling - public
  * ---------------------------------------------------------------------------------
  */
 
@@ -178,86 +255,137 @@ void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t
 Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
   // see header file for class documentation
 
+  if (fReaderList == NULL or fSourceList == NULL)
+  {
+    HLTError("Must first create a source list with a call to CreateSourcesList().");
+    return -1;
+  }
+  
   Int_t iResult = 0;
 
+  // HAck Jochen
+  //----
+  detector="ALL";
+
   // -- Check if LibManager is present
   if ( ! fLibManager ) {
-    HLTError(Form("No LibManager present."));
+    HLTError("No LibManager present.");
     return -1;
   }
   
   // -- Check if already connected and state has not changed
   if ( fStateHasChanged == kFALSE && IsConnected() ) {
-    HLTInfo(Form("No need for reconnection."));
-    return iResult;
+    HLTInfo("No need for reconnection.");
+    return 0;
   }
   
   // -- If already connected, disconnect before connect
-  if ( IsConnected() )
+  //    or if ReaderList already filled
+  if ( IsConnected() || fReaderList->GetSize() != 0 ) {
+    HLTInfo(Form("IsConnected: %d      fReaderList.Size:   %d", IsConnected(), fReaderList->GetSize()));
     DisconnectHOMER();
-  
+  }
   // -- Create the Readoutlist
   UShort_t* sourcePorts = new UShort_t [fSourceList->GetEntries()];
-  const char ** sourceHostnames = new const char* [fSourceList->GetEntries()];
+  const Char_t ** sourceHostnames = new const Char_t* [fSourceList->GetEntries()];
+  for(Int_t i = 0; i < fSourceList->GetEntries(); i++) {
+   sourceHostnames[i] = "";
+  }
   UInt_t sourceCount = 0;
-  
+
   CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
   if ( sourceCount == 0 ) {
-    HLTError(Form("No sources selected, aborting."));
+    HLTError("No sources selected, aborting.");
+    delete [] sourcePorts;
+    delete [] sourceHostnames;
     return -2;
   }
 
+  // ***
   // *** Connect to data sources
-  if ( !fReader )
-    fReader = fLibManager->OpenReader( sourceCount, sourceHostnames, sourcePorts );
+  // ***
   
-  iResult = fReader->GetConnectionStatus();
-  if ( iResult ) {
-    // -- Connection failed
-
-    UInt_t ndx = fReader->GetErrorConnectionNdx();
+  for (UInt_t idx = 0; idx < sourceCount; idx++) {
+    
+    if (sourcePorts[idx] > 60000)
+      continue;
 
-    if ( ndx < sourceCount ) {
-      HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
-                   sourceHostnames[ndx], sourcePorts[ndx], strerror(iResult), iResult));
-    }
-    else {
-      HLTError(Form("Error establishing connection to unknown source with index %d: %s (%d)",
-                   ndx, strerror(iResult), iResult));
+    HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx]));
+    
+    fReaderList->Add(dynamic_cast<TObject*>(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx])));
+    AliHLTHOMERReader *reader = static_cast<AliHLTHOMERReader*>(fReaderList->Last());
+    if ( !reader ) {
+      HLTError("Adding reader failed, aborting");
+      delete [] sourcePorts;
+      delete [] sourceHostnames;
+      return -3;
     }
 
-    if ( fReader )
-      fLibManager->DeleteReader( fReader );
-    fReader = NULL;
-  }
-  else {
-    // -- Connection ok - set reader
-    fConnected = kTRUE;
+    if ( (iResult = reader->GetConnectionStatus()) )  {
 
-    HLTInfo(Form("Connection established."));
-  }
+      // -- Connection to source failed
+      
+      HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
+                   sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
+
+      if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) {
+       HLTInfo("The failed connection is on localhost. is SSH tunnel up????? ");
+       HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'",
+                    sourcePorts[idx], sourcePorts[idx]));
+      }
+      
+      // -- Remove reader
+      fReaderList->RemoveLast();
+
+      if ( reader )
+       fLibManager->DeleteReader( reader );
+      reader = NULL;
+      
+      HLTInfo(Form("Removed source %d,  %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx]));
+      
+    } 
+    else {
+      // -- Connection succeded
+      fConnected = kTRUE;
 
+      HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx]));
+    }
+    
+  } // for (Int_t idx = 0; idx < sourceCount; idx++) {
+  
   delete[] sourceHostnames;
   delete[] sourcePorts;
 
   return iResult;
+
 }
 
 //##################################################################################
 void AliHLTHOMERManager::DisconnectHOMER(){
   // see header file for class documentation
 
-  if ( ! IsConnected() )
-    return;
-
-  if ( fReader )
-    fLibManager->DeleteReader( fReader );
-  fReader = NULL;
-
+  HLTInfo("Disconnecting");
+
+  if ( fReaderList && fLibManager ) {
+    HLTInfo("Deleting readerlist and libmanager");
+    TIter next(fReaderList);
+    TObject * object = NULL;
+    while ( ( object = next()) ) 
+      fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
+      
+
+    HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
+    fReaderList->Clear();
+    HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
+    delete fReaderList;
+    fReaderList = new TList ();
+    HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
+  }
+  
   fStateHasChanged = kTRUE;
   fConnected = kFALSE;
-
-  HLTInfo(Form("Connection closed."));
+  
+  HLTInfo("Connection closed.");
 
   return;
 }
@@ -273,7 +401,7 @@ Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
 
   iResult = ConnectHOMER(detector);
   if ( iResult ) {
-    HLTError(Form("Error reconnecting."));
+    HLTError("Error reconnecting.");
   }
 
   return iResult;
@@ -287,97 +415,143 @@ Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
 
 //##################################################################################
 Int_t AliHLTHOMERManager::NextEvent(){
   // see header file for class documentation
-
+  
   Int_t iResult = 0;
   Int_t iRetryCount = 0;
   
-  if ( !IsConnected() || fStateHasChanged )
-    ConnectHOMER();
-  
-  if ( !fReader || !IsConnected() ) {
-    HLTWarning(Form( "Not connected yet." ));
+  if ( !IsConnected() || fStateHasChanged ) {
+    HLTInfo("Not connected or state has changed, returning to AliEveHOMERManager, which will deal with this situation");
+    //    cout << "connectecd  " << IsConnected()  << "haschanged  "<<fStateHasChanged << endl;
+    return 55;//ConnectHOMER();
+  }
+  if ( !IsConnected() ) {
+    HLTWarning("Not connected yet.");
     return -1;
   }
 
-  //  fReader->SetEventRequestAdvanceTime( 20000000 /*timeout in us*/ );
+  // -- Reset asyncronous BlockList
+  fAsyncBlockList->Delete();
 
-  // -- Read next event data and error handling for HOMER (error codes and empty blocks)
-  while( 1 ) {
+  // ***
+  // *** Loop over all readers and get new event data
+  // ***
+  
+  TIter next(fReaderList);
+  TObject * object = NULL;
+  
+  while( (object = next()) ) {
     
-    iResult = fReader->ReadNextEvent( 40000000 /*timeout in us*/);
-
-    if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
-      HLTError(Form("No Connection to source %d: %s (%d)", 
-                   fReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
-      return -iResult;
-    }
-    else if ( iResult == 110 ) {
-      HLTError(Form("Timout occured, reading event from source %d: %s (%d)", 
-                   fReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
-      return -iResult;
-    }
-    else if ( iResult == 56) {
-      ++iRetryCount;
-
-      if ( iRetryCount >= 20 ) {
-       HLTError(Form("Retry Failed: Error reading event from source %d: %s (%d)", 
-                     fReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
-       return -iResult;
+    fCurrentReader = static_cast<AliHLTHOMERReader*>(object);
+    
+    // -- Read next event data and error handling for HOMER (error codes and empty blocks)
+    while ( 1 ) {
+      
+      iResult = fCurrentReader->ReadNextEvent( 40000000 /*timeout in us*/);
+      
+      if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
+       HLTError(Form("No connection to source %d: %s (%d)", 
+                     fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
+       break;
+      } 
+      else if ( iResult == 110 ) {
+       HLTError(Form("Timeout occured, reading event from source %d: %s (%d)", 
+                     fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
+       break;
+      } 
+      else if ( iResult == 56 ) {
+       ++iRetryCount;
+      
+       if ( iRetryCount >= 20 ) {
+         HLTError(Form("Retry Failed: Error reading event from source %d: %s (%d), returning", 
+                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
+         break;
+       } 
+       else {
+         HLTError(Form("Retry: Error reading event from source %d: %s (%d), making another attempt (no %d out of 20)", 
+                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult, iRetryCount));
+         //break;
+         continue;
+       }
       }
+      else if ( iResult ) {
+       HLTError(Form("General Error reading event from source %d: %s (%d), giving up", 
+                     fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
+       fConnected = kFALSE;
+       break;
+      } 
       else {
-       HLTError(Form("Retry: Error reading event from source %d: %s (%d)", 
-                     fReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
-       continue;
+       HLTDebug("Successfully read out event from source");
+       break;
       }
+
+    } // while( 1 ) {
+    
+    // -- Check if event could be read
+    if ( iResult ) {
+      HLTInfo("Reading event from source failed");
+      continue;
     }
-    else if ( iResult ) {
-      HLTError(Form("General Error reading event from source %d: %s (%d)", 
-                   fReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
-      fConnected = kFALSE;
-      return -iResult;
-    }
-    else {
-      break;
+
+    // -- Handle Blocks from current reader
+    iResult = HandleBlocks();
+    if ( iResult ) {
+      HLTError("Handling of blocks failed.");
     }
-  } // while( 1 ) {
 
-  // -- Get blockCnt and eventID
-  fNBlks = static_cast<ULong_t>(fReader->GetBlockCnt());
-  fEventID = static_cast<ULong64_t>(fReader->GetEventID());
-  fCurrentBlk = 0;
+  } // while( (object = next()) ) {
 
-  HLTInfo(Form("Event 0x%016LX (%Lu) with %lu blocks", fEventID, fEventID, fNBlks));
+  return iResult;  
+}
 
-#if EVE_DEBUG
-  // Loop for Debug only
-  for ( ULong_t ii = 0; ii < fNBlks; ii++ ) {
-    Char_t tmp1[9], tmp2[5];
-    memset( tmp1, 0, 9 );
-    memset( tmp2, 0, 5 );
-    void *tmp11 = tmp1;
-    ULong64_t* tmp12 = static_cast<ULong64_t*>(tmp11);
-    *tmp12 = fReader->GetBlockDataType(ii);
-    void *tmp21 = tmp2;
-    ULong_t* tmp22 = static_cast<ULong_t*>(tmp21);
-    *tmp22 = fReader->GetBlockDataOrigin(ii);
-    HLTInfo(Form( "Block %lu length: %lu - type: %s - origin: %s - spec 0x%08X",
-                 ii, fReader->GetBlockDataLength(ii), tmp1, tmp2, fReader->GetBlockDataSpec(ii) ));
-  } // end for ( ULong_t ii = 0; ii < fNBlks; ii++ ) {
-#endif
+/* ---------------------------------------------------------------------------------
+ *                           Buffer Handling - public
+ * ---------------------------------------------------------------------------------
+ */
 
-  // -- Create BlockList
-  if ( fNBlks > 0 ) {
-    HLTInfo(Form("Create Block List"));
-    CreateBlockList();
-  }
-  else {
-    HLTWarning(Form("Event 0x%016LX (%Lu) with %lu blocks", fEventID, fEventID, fNBlks));
-  }
-    
-  return iResult;
+//##################################################################################
+Int_t AliHLTHOMERManager::NavigateEventBufferBack() { 
+  // see header file for class documentation
+
+  // -- reached the end of the buffer
+  if ( fNavigateBufferIdx == fBufferLowIdx )
+    return -1;
+
+  Int_t newIdx = fNavigateBufferIdx - 1;
+  if ( newIdx == -1 )
+    newIdx = BUFFERSIZE-1;
+
+  fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
+
+  return newIdx;
 }
 
+//##################################################################################
+Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
+  // see header file for class documentation
+
+  HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
+
+  // -- reached the top of the buffer
+  if ( fNavigateBufferIdx == fBufferTopIdx )
+    return -1;
+
+  Int_t newIdx = fNavigateBufferIdx + 1;
+  if ( newIdx == BUFFERSIZE )
+    newIdx = 0;
+  
+  fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
+  fNEventsAvailable -= 1;
+
+  HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
+
+
+  return 0;
+}
+
+ ///////////////////////////////////////////////////////////////////////////////////
+
 /*
  * ---------------------------------------------------------------------------------
  *                            Connection Handling - private
@@ -395,11 +569,15 @@ void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort
   TIter next( fSourceList );
   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
 
+    ///Don't use sources from dev cluster
+    if(source->GetPort() > 60000) continue;
+
     // -- If detector NO detector name given
     if ( ! detector.CompareTo("ALL") ) {
       // -- Continue if source is not selected
-      if ( ! source->IsSelected() )
-       continue;
+      // HACK Jochen
+      //if ( ! source->IsSelected() )
+      //       continue;
     }
     // -- DetectorName given
     else {
@@ -437,22 +615,59 @@ void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort
 
 /*
  * ---------------------------------------------------------------------------------
- *                            Event Handling
+ *                          Buffer Handling - private
  * ---------------------------------------------------------------------------------
  */
 
-
 //##################################################################################
-void AliHLTHOMERManager::CreateBlockList() {
+void AliHLTHOMERManager::AddBlockListToBuffer() {
   // see header file for class documentation
+  // -- Check if event is already in buffer
+  ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
+  
+  if ( fEventID[fBufferTopIdx] == eventID ) {
+    HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
+    return;
+  }
 
-  // -- Initialize block list
-  if ( fBlockList != NULL )
-    delete fBlockList;
-  fBlockList = NULL;
+  // -- Check if event should be selected on basis of trigger string
+  if( fTriggerString.CompareTo("ALL") ){
+    if ( !CheckTriggerDecision() ) {
+      HLTInfo("Event not triggered");
+      return;
+    } else {
+      HLTInfo("Event triggered");
+    }
+  }
+  else {
+    HLTDebug("No trigger selection.");
+  }
+
+  // -- Set Top mark 
+  ++fBufferTopIdx;
+  if ( fBufferTopIdx == BUFFERSIZE )
+    fBufferTopIdx = 0;
+
+  // -- Change the low mark if necessary
+  if ( fBufferLowIdx == -1 )
+    fBufferLowIdx = 0;
+  else if ( fBufferTopIdx == fBufferLowIdx ) {
+    ++fBufferLowIdx;
+    if ( fBufferLowIdx == BUFFERSIZE )
+      fBufferLowIdx = 0;
+  }
 
+
+  // -- Fill EventID
+  fEventID[fBufferTopIdx] = eventID;
+
+  // -- Clear Buffer slot
+  (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
+  if(fBlockList->IsOwner()) HLTWarning("block list is owner!!");
+  HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
+  //fBlockList->Clear();
   fBlockList = new TList();
-  fBlockList->SetOwner(kTRUE);
+  HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
 
   GetFirstBlk();
 
@@ -466,37 +681,163 @@ void AliHLTHOMERManager::CreateBlockList() {
     
     // -- Check sources list if block is requested
     if ( CheckIfRequested( block ) ) {
-      fBlockList->Add( block );
+      (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
+      fBlockList->Add(block);
     }
     else {
       // XXX HACK Jochen
-      fBlockList->Add( block );
-      //      delete block;
-      //      block = NULL;
+      (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
+      fBlockList->Add(block);
+      // delete block;
+      // block = NULL;
     }
  
   } while( GetNextBlk() );
+
+  //We have one more event available
+  fNEventsAvailable++;
+  HLTInfo(Form("fNEventsAvailable %d", fNEventsAvailable));
+  return;
+}
+
+//##################################################################################
+void AliHLTHOMERManager::AddToAsyncBlockList() {
+  // see header file for class documentation
+
+  HLTInfo("Adding blocks to the asynchroneous block list");
+
+  GetFirstBlk();
+
+  do {
+    
+    AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
+    block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
+                    GetBlkType(), GetBlkSpecification() );
     
+
+    fAsyncBlockList->Add( block );
+  } while( GetNextBlk() );
+
   return;
 }
+//__________________________________________________________________________________
+void AliHLTHOMERManager::AddToBlockList() {
+  // see header file for class documentation
+  HLTInfo("Adding blocks to the synchroneous block list");
 
-/*
- * ---------------------------------------------------------------------------------
- *                            BlockHandling
- * ---------------------------------------------------------------------------------
- */
+  ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
+  
+  if ( fEventId == eventID ) {
+    HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
+    return;
+  }
+
+  fEventId = eventID;
+
+  GetFirstBlk();
+  do {
+
+    AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
+    block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
+                    GetBlkType(), GetBlkSpecification() );
+    fBlockList->Add( block );
+  
+  } while( GetNextBlk() );  
+}
+
+//__________________________________________________________________________________
+TList* AliHLTHOMERManager::GetBlockListEventBuffer() {
+  // see header file for class documentation
+
+  if(fBlockList)
+    return fBlockList;
+  else 
+    return NULL;
+
+
+}
+
+
+//__________________________________________________________________________________
+Int_t AliHLTHOMERManager::HandleBlocks() {
+  // see header file for class documentation
+  
+  Int_t iResult = 0;
+
+  // -- Get blockCnt and eventID
+  fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt());
+  ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
+  fCurrentBlk = 0;
+
+  // -- Check if blocks present
+  if ( fNBlks ==  0 ) {
+    HLTWarning(Form("Event 0x%016lX (%lu) with no blocks", eventID, eventID));
+    return -1;
+  }
+
+  HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks));
+    
+  if ( IsSyncBlocks() ) {
+    //AddBlockListToBuffer();
+    fBlockList->Clear();
+    AddToBlockList();
+  } else {
+    AddToAsyncBlockList();
+  }
+
+  return iResult;
+}
+
+//__________________________________________________________________________________
+Bool_t AliHLTHOMERManager::IsSyncBlocks() {
+  // see header file for class documentation
+  
+  Bool_t bResult = kFALSE;
+
+  GetFirstBlk();
+  
+  do {          
+    
+    if ( !GetBlkType().CompareTo("ALIESDV0")) {
+      bResult = kTRUE;
+      break;
+    }
+
+    if ( !GetBlkType().CompareTo("GLOBTRIG")) {
+      bResult = kTRUE;
+      break;
+    }
+    
+    if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
+      AliHLTHOMERBlockDesc blockDesc;
+      
+      blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
+                         GetBlkType(), GetBlkSpecification() );
+      if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
+
+       bResult = kTRUE;
+       break;
+      }
+    }
+
+  } while( GetNextBlk() );
+
+
+  return bResult;
+}
 
 //##################################################################################
 void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
   // see header file for class documentation
   // Get pointer to current block in current event
    
-  if ( !fReader || !IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+  if ( !fCurrentReader || !IsConnected() ) {
+    HLTError("Not connected yet.");
     return NULL;
   }
   if ( ndx < static_cast<Int_t>(fNBlks) )
-    return  const_cast<void*> (fReader->GetBlockData(ndx));
+    return  const_cast<void*> (fCurrentReader->GetBlockData(ndx));
   else
     return NULL;
 }
@@ -505,13 +846,13 @@ void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
 ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
   // see header file for class documentation
    
-  if ( !fReader || !IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+  if ( !fCurrentReader || !IsConnected() ) {
+    HLTError("Not connected yet.");
     return 0;
   }
   
   if ( ndx < static_cast<Int_t>(fNBlks) )
-    return static_cast<ULong_t> (fReader->GetBlockDataLength(ndx));
+    return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx));
   else
     return 0;
 }
@@ -523,8 +864,8 @@ TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
   TString origin = "";
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+  if ( !fCurrentReader || ! IsConnected() ) {
+    HLTError("Not connected yet.");
     return origin;
   }
 
@@ -540,7 +881,7 @@ TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
     Char_t array[4];
   } reverseOrigin;
 
-  reverseOrigin.data = static_cast<UInt_t>(fReader->GetBlockDataOrigin(ndx));
+  reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx));
 
   // -- Reverse the order
   for (Int_t ii = 3; ii >= 0; ii-- )
@@ -559,8 +900,8 @@ TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
   TString type = "";
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+  if ( !fCurrentReader || ! IsConnected() ) {
+    HLTError("Not connected yet.");
     return type;
   }
 
@@ -576,7 +917,7 @@ TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
     Char_t array[8];
   } reverseType;
 
-  reverseType.data = static_cast<ULong64_t> (fReader->GetBlockDataType(ndx));
+  reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx));
 
   // -- Reverse the order
   for (Int_t ii = 7; ii >= 0; ii-- )
@@ -593,8 +934,8 @@ ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
   // see header file for class documentation
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+  if ( !fCurrentReader || ! IsConnected() ) {
+    HLTError("Not connected yet.");
     return 0;
   }
 
@@ -604,7 +945,7 @@ ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
     return 0;
   }
 
-  return static_cast<ULong_t>(fReader->GetBlockDataSpec(ndx));
+  return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx));
 }
 
 //##################################################################################
@@ -644,3 +985,79 @@ Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
   return requested;
 }
 
+/* ---------------------------------------------------------------------------------
+ *                          Trigger Handling - private
+ * ---------------------------------------------------------------------------------
+ */
+
+//##################################################################################
+Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
+  // see header file for class documentation
+
+  Bool_t triggered = kFALSE;
+
+  if ( !fCurrentReader || !IsConnected() ) {
+    HLTError("Not connected yet.");
+    return kFALSE;
+  }
+
+  AliHLTHOMERBlockDesc blockDesc;
+
+  GetFirstBlk();
+  
+  // -- Fill block list
+  Bool_t foundTriggerBlock = kFALSE;
+  
+  do {
+    if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) {
+      blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
+                         GetBlkType(), GetBlkSpecification() );
+
+      if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
+
+       foundTriggerBlock = kTRUE;
+       break;
+      }
+      
+    }
+  } while( GetNextBlk() );
+  
+  if ( !foundTriggerBlock ) {
+    HLTError("No trigger decision object found");
+    return kFALSE;
+  }
+
+  // -- Get the global decision object
+  AliHLTGlobalTriggerDecision* globalDecision = 
+    static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject());
+
+  if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) {
+    triggered = globalDecision->EventTriggered();
+  } 
+  else {
+    
+    for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
+       
+      const AliHLTTriggerDecision* triggerDecision = 
+       reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx));
+    
+      if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) {
+       triggered = triggerDecision->EventTriggered();
+       break;
+      }
+    } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
+  }
+
+
+
+  if ( triggered ) {
+    fRetryNextEvent = kFALSE;
+    fNEventsNotTriggered = 0;
+  }
+  else {
+    fRetryNextEvent = kTRUE;
+    ++fNEventsNotTriggered;
+  }
+
+  return triggered;
+}