]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTHOMERManager.cxx
Major update required to handle old and new AliHLTEventDDL structures within HLT...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
index 85794e4857e810efa7cd5baaab184325731de168..0e108dc78aa20727af23c699307193a14ca42edd 100644 (file)
@@ -32,7 +32,7 @@
    using namespace std;
 #endif
 
-#define EVE_DEBUG 1
+#define EVE_DEBUG 0
 
 #include "AliHLTHOMERManager.h"
 // -- -- -- -- -- -- -- 
 #include "AliHLTHOMERSourceDesc.h"
 #include "AliHLTHOMERBlockDesc.h"
 // -- -- -- -- -- -- -- 
+#include "AliHLTGlobalTriggerDecision.h"
+#include "AliHLTTriggerDecision.h"
+//---------------------------
+
 ClassImp(AliHLTHOMERManager)
 
 /*
@@ -53,13 +57,22 @@ ClassImp(AliHLTHOMERManager)
   fLibManager(new AliHLTHOMERLibManager),
   fStateHasChanged(kTRUE),
   fProxyHandler(NULL),
-  fReader(NULL),
+  fCurrentReader(NULL),
+  fReaderList(NULL),
   fSourceList(NULL),
-  fBlockList(NULL),
   fNBlks(0),
-  fEventID(0),
+  fEventID(),
   fCurrentBlk(0),
-  fConnected(kFALSE) {
+  fAsyncBlockList(NULL),
+  fEventBuffer(NULL),
+  fBufferTopIdx(-1),
+  fBufferLowIdx(-1),
+  fCurrentBufferIdx(-1),
+  fNavigateBufferIdx(-1),
+  fConnected(kFALSE), 
+  fTriggerString("ALL"), 
+  fNEventsNotTriggered(0),
+  fRetryNextEvent(kFALSE) {
   // see header file for class documentation
   // or
   // refer to README to build package
@@ -73,12 +86,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,9 +110,17 @@ AliHLTHOMERManager::~AliHLTHOMERManager() {
     delete fSourceList;
   fSourceList = NULL;
 
-  if ( fBlockList != NULL )
-    delete fBlockList;
-  fBlockList = NULL;
+  if ( fEventBuffer ) {
+    fEventBuffer->Clear();
+    delete fEventBuffer;
+  }
+  fEventBuffer = NULL;
+
+  if ( fAsyncBlockList ) {
+    fAsyncBlockList->Clear();
+    delete fAsyncBlockList;
+  }
+  fAsyncBlockList = NULL;
 }
 
 //##################################################################################
@@ -99,6 +129,7 @@ Int_t AliHLTHOMERManager::Initialize() {
 
   Int_t iResult = 0;
 
+  // -- Initialize ProxyHandler
   if ( !fProxyHandler )
     fProxyHandler = new AliHLTHOMERProxyHandler();
   
@@ -112,6 +143,29 @@ Int_t AliHLTHOMERManager::Initialize() {
     HLTError(Form("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 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;
 }
 
@@ -141,6 +195,10 @@ Int_t AliHLTHOMERManager::CreateSourcesList() {
   else if ( iResult > 0 ) {
     HLTWarning(Form("No active services found."));
   }
+  else if ( fSourceList->IsEmpty() ) {
+    HLTWarning(Form("No active services in the list."));
+    iResult = 2;
+  }
   else {
      HLTInfo(Form("New sources list created."));
 
@@ -166,7 +224,7 @@ void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t
 
 /*
  * ---------------------------------------------------------------------------------
- *                         Connection Handling -oublic
+ *                         Connection Handling - public
  * ---------------------------------------------------------------------------------
  */
 
@@ -176,81 +234,118 @@ Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
 
   Int_t iResult = 0;
 
+  // HAck Jochen
+  //----
+  detector="ALL";
+
+  // -- Check if LibManager is present
+  if ( ! fLibManager ) {
+    HLTError(Form("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;
+    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()];
   UInt_t sourceCount = 0;
 
   CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
   if ( sourceCount == 0 ) {
     HLTError(Form("No sources selected, aborting."));
-    return -1;
+    return -2;
   }
 
+  // ***
   // *** Connect to data sources
-  if ( !fReader && fLibManager )
-    fReader = fLibManager->OpenReader( sourceCount, sourceHostnames, sourcePorts );
-  else {
-    HLTError(Form("No LibManager present."));
-    return -2;
-  }
+  // ***
+  
+  for (UInt_t idx = 0; idx < sourceCount; idx++) {
     
-  iResult = fReader->GetConnectionStatus();
-  if ( iResult ) {
-    // -- Connection failed
+    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(Form("Adding reader failed, aborting"));
+      return -3;
+    }
 
-    UInt_t ndx = fReader->GetErrorConnectionNdx();
+    if ( (iResult = reader->GetConnectionStatus()) )  {
 
-    if ( ndx < sourceCount ) {
+      // -- Connection to source failed
+      
       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));
-    }
+                   sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
 
-    if ( fReader )
-      fLibManager->DeleteReader( fReader );
-    fReader = NULL;
-  }
-  else {
-    // -- Connection ok - set reader
-    fConnected = kTRUE;
+      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();
 
-    HLTInfo(Form("Connection established."));
-  }
+      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;
+  HLTInfo("Disconnecting");
 
-  if ( fReader )
-    fLibManager->DeleteReader( fReader );
-  fReader = NULL;
+  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."));
 
   return;
@@ -279,97 +374,149 @@ 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 ( !fReader || ! IsConnected() ) {
+  
+  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(Form( "Not connected yet." ));
     return -1;
   }
 
-  //  fReader->SetEventRequestAdvanceTime( 20000000 /*timeout in us*/ );
+  // -- Reset asyncronous BlockList
+  fAsyncBlockList->Clear();
 
-  // -- 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(Form("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));
+  // -- Check if NextEvent should be recalled, 
+  //    to catch the next event with a trigger
+  if ( fRetryNextEvent ) {
+    usleep(1000000);
+    fRetryNextEvent = kFALSE;
+    
+    HLTInfo(Form("Checked trigger of %d events, without triggering", fNEventsNotTriggered));
+    return NextEvent();
+  }
+  else
+    return 0;  
+}
 
-#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
+
+  // -- reached the top of the buffer
+  if ( fNavigateBufferIdx == fBufferTopIdx )
+    return -1;
+
+  Int_t newIdx = fNavigateBufferIdx + 1;
+  if ( newIdx == BUFFERSIZE )
+    newIdx = 0;
+  
+  fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
+
+  return newIdx;
+}
+
+ ///////////////////////////////////////////////////////////////////////////////////
+
 /*
  * ---------------------------------------------------------------------------------
  *                            Connection Handling - private
@@ -390,8 +537,9 @@ void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort
     // -- 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 {
@@ -429,22 +577,56 @@ 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;
+  }
+
+  // -- 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;
+  }
+
+  fNavigateBufferIdx = fCurrentBufferIdx = fBufferTopIdx;    
 
-  // -- Initialize block list
-  if ( fBlockList != NULL )
-    delete fBlockList;
-  fBlockList = NULL;
+  // -- Fill EventID
+  fEventID[fBufferTopIdx] = eventID;
+
+  // -- Clear Buffer slot
+  (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
 
-  fBlockList = new TList();
-  fBlockList->SetOwner(kTRUE);
 
   GetFirstBlk();
 
@@ -458,36 +640,157 @@ void AliHLTHOMERManager::CreateBlockList() {
     
     // -- Check sources list if block is requested
     if ( CheckIfRequested( block ) ) {
-      fBlockList->Add( block );
-      
+      (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
     }
     else {
-      delete block;
-      block = NULL;
+      // XXX HACK Jochen
+      (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
+      // delete block;
+      // block = NULL;
     }
  
   } while( GetNextBlk() );
+
+  return;
+}
+
+//##################################################################################
+void AliHLTHOMERManager::AddToAsyncBlockList() {
+  // see header file for class documentation
+
+  HLTInfo("Adding blocks to the asynchroneous block list");
+
+  GetFirstBlk();
+
+  // -- Fill block list
+  do {
     
+    // -- Create new block
+    AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
+    block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
+                    GetBlkType(), GetBlkSpecification() );
+    
+    // -- Check sources list if block is requested
+    if ( CheckIfRequested( block ) ) 
+      fAsyncBlockList->Add( block );
+    else {
+      // XXX HACK Jochen
+      fAsyncBlockList->Add( block );
+      // delete block;
+      // block = NULL;
+    }
+  } while( GetNextBlk() );
+
   return;
 }
+//##################################################################################
+TList* AliHLTHOMERManager::GetBlockListEventBuffer( Int_t idx ) {
+  // see header file for class documentation
+
+  if ( idx == -1 )
+    return NULL;
+
+  return reinterpret_cast<TList*>((*fEventBuffer)[idx]);
+
+}
 
 /*
  * ---------------------------------------------------------------------------------
- *                            BlockHandling
+ *                          Block Handling - private
  * ---------------------------------------------------------------------------------
  */
 
+//##################################################################################
+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 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 = fCurrentReader->GetBlockDataType(ii);
+    void *tmp21 = tmp2;
+    ULong_t* tmp22 = static_cast<ULong_t*>(tmp21);
+    *tmp22 = fCurrentReader->GetBlockDataOrigin(ii);
+    HLTInfo(Form( "Block %lu length: %lu - type: %s - origin: %s - spec 0x%08X",
+                 ii, fCurrentReader->GetBlockDataLength(ii), tmp1, tmp2, fCurrentReader->GetBlockDataSpec(ii) ));
+  } // end for ( ULong_t ii = 0; ii < fNBlks; ii++ ) {
+#endif
+    
+  // -- Check if blocks are from syncronous source
+
+   if ( IsSyncBlocks() )
+     AddBlockListToBuffer();
+   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("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() ) {
+  if ( !fCurrentReader || !IsConnected() ) {
     HLTError(Form("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;
 }
@@ -496,13 +799,13 @@ void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
 ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
   // see header file for class documentation
    
-  if ( !fReader || !IsConnected() ) {
+  if ( !fCurrentReader || !IsConnected() ) {
     HLTError(Form("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;
 }
@@ -514,7 +817,7 @@ TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
   TString origin = "";
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
+  if ( !fCurrentReader || ! IsConnected() ) {
     HLTError(Form("Not connected yet."));
     return origin;
   }
@@ -531,7 +834,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-- )
@@ -550,7 +853,7 @@ TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
   TString type = "";
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
+  if ( !fCurrentReader || ! IsConnected() ) {
     HLTError(Form("Not connected yet."));
     return type;
   }
@@ -567,7 +870,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-- )
@@ -584,7 +887,7 @@ ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
   // see header file for class documentation
 
   // -- Check for Connection
-  if ( !fReader || ! IsConnected() ) {
+  if ( !fCurrentReader || ! IsConnected() ) {
     HLTError(Form("Not connected yet."));
     return 0;
   }
@@ -595,7 +898,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));
 }
 
 //##################################################################################
@@ -613,7 +916,7 @@ Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
     // -- Check if source is selected
     if ( ! source->IsSelected() )
       continue;
-        
+    
     // -- Check if detector matches
     if ( source->GetSourceName().CompareTo( block->GetBlockName() ) )
       continue;
@@ -623,7 +926,7 @@ Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
 
   } // while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
   
-#if 0 //EVE_DEBUG
+#if EVE_DEBUG
   if ( requested ) {
     HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); 
   }
@@ -635,3 +938,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(Form("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(Form("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;
+}