]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTHOMERManager.cxx
store all HLTOUT data blocks of an event in one DDL and use a round robin schedule...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
index 2b2229c797fd51f0064892a7c657f0a528c655b1..18ad84efe8da307767e2da17db6ab2092ddeb114 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.                         *
@@ -62,17 +62,22 @@ ClassImp(AliHLTHOMERManager)
   fSourceList(NULL),
   fNBlks(0),
   fEventID(),
+  fEventId(-1),
   fCurrentBlk(0),
   fAsyncBlockList(NULL),
-  fEventBuffer(NULL),
+  fBlockList(NULL),
+   fEventBuffer(NULL),
   fBufferTopIdx(-1),
   fBufferLowIdx(-1),
   fCurrentBufferIdx(-1),
   fNavigateBufferIdx(-1),
+  fNEventsAvailable(0),
   fConnected(kFALSE), 
   fTriggerString("ALL"), 
   fNEventsNotTriggered(0),
-  fRetryNextEvent(kFALSE) {
+  fRetryNextEvent(kFALSE),
+  fIsBlockOwner(kTRUE)
+{
   // see header file for class documentation
   // or
   // refer to README to build package
@@ -116,8 +121,14 @@ AliHLTHOMERManager::~AliHLTHOMERManager() {
   }
   fEventBuffer = NULL;
 
+  if(fBlockList) {
+    fBlockList->Clear();
+    delete fBlockList;
+  }
+  fBlockList = NULL;
+
   if ( fAsyncBlockList ) {
-    fAsyncBlockList->Clear();
+    fAsyncBlockList->Delete();
     delete fAsyncBlockList;
   }
   fAsyncBlockList = NULL;
@@ -127,6 +138,8 @@ AliHLTHOMERManager::~AliHLTHOMERManager() {
 Int_t AliHLTHOMERManager::Initialize() {
   // see header file for class documentation
 
+  HLTInfo("Initializing");
+
   Int_t iResult = 0;
 
   // -- Initialize ProxyHandler
@@ -136,11 +149,11 @@ Int_t AliHLTHOMERManager::Initialize() {
   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
@@ -154,6 +167,12 @@ Int_t AliHLTHOMERManager::Initialize() {
     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 );
@@ -179,8 +198,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;
@@ -190,17 +215,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
@@ -232,6 +257,12 @@ 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
@@ -240,29 +271,35 @@ Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
 
   // -- 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."));
+    HLTInfo("No need for reconnection.");
     return 0;
   }
   
   // -- If already connected, disconnect before connect
   //    or if ReaderList already filled
-  if ( IsConnected() || fReaderList->GetSize() != 0 )
+  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_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;
   }
 
@@ -272,12 +309,17 @@ Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
   
   for (UInt_t idx = 0; idx < sourceCount; idx++) {
     
+    if (sourcePorts[idx] > 60000)
+      continue;
+
     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"));
+      HLTError("Adding reader failed, aborting");
+      delete [] sourcePorts;
+      delete [] sourceHostnames;
       return -3;
     }
 
@@ -324,24 +366,28 @@ Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
 void AliHLTHOMERManager::DisconnectHOMER(){
   // see header file for class documentation
 
-  if ( ! IsConnected() )
-    return;
+  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 = NULL;
+    fReaderList = new TList ();
+    HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
   }
   
   fStateHasChanged = kTRUE;
   fConnected = kFALSE;
-
-  HLTInfo(Form("Connection closed."));
+  
+  HLTInfo("Connection closed.");
 
   return;
 }
@@ -357,7 +403,7 @@ Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
 
   iResult = ConnectHOMER(detector);
   if ( iResult ) {
-    HLTError(Form("Error reconnecting."));
+    HLTError("Error reconnecting.");
   }
 
   return iResult;
@@ -377,16 +423,18 @@ Int_t AliHLTHOMERManager::NextEvent(){
   Int_t iResult = 0;
   Int_t iRetryCount = 0;
   
-  if ( !IsConnected() || fStateHasChanged ) 
-    ConnectHOMER();
-  
+  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." ));
+    HLTWarning("Not connected yet.");
     return -1;
   }
 
   // -- Reset asyncronous BlockList
-  fAsyncBlockList->Clear();
+  fAsyncBlockList->Delete();
 
   // ***
   // *** Loop over all readers and get new event data
@@ -436,34 +484,27 @@ Int_t AliHLTHOMERManager::NextEvent(){
        break;
       } 
       else {
+       HLTDebug("Successfully read out event from source");
        break;
       }
 
     } // while( 1 ) {
     
     // -- Check if event could be read
-    if ( iResult )
+    if ( iResult ) {
+      HLTInfo("Reading event from source failed");
       continue;
-    
+    }
+
     // -- Handle Blocks from current reader
     iResult = HandleBlocks();
     if ( iResult ) {
-      HLTError(Form("Handling of blocks failed."));
+      HLTError("Handling of blocks failed.");
     }
 
   } // while( (object = next()) ) {
 
-  // -- 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;  
+  return iResult;  
 }
 
 /* ---------------------------------------------------------------------------------
@@ -492,6 +533,8 @@ Int_t AliHLTHOMERManager::NavigateEventBufferBack() {
 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;
@@ -501,8 +544,12 @@ Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
     newIdx = 0;
   
   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
+  fNEventsAvailable -= 1;
 
-  return newIdx;
+  HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
+
+
+  return 0;
 }
 
  ///////////////////////////////////////////////////////////////////////////////////
@@ -524,6 +571,9 @@ 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
@@ -574,25 +624,25 @@ void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort
 //##################################################################################
 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));
+    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(Form("Event 0x%016LX (%Lu) is not triggered by %s.", 
-                  eventID, eventID, fTriggerString.Data()));
+      HLTInfo("Event not triggered");
       return;
+    } else {
+      HLTInfo("Event triggered");
     }
   }
   else {
-    HLTInfo("No trigger selection.");
+    HLTDebug("No trigger selection.");
   }
 
   // -- Set Top mark 
@@ -609,14 +659,17 @@ void AliHLTHOMERManager::AddBlockListToBuffer() {
       fBufferLowIdx = 0;
   }
 
-  fNavigateBufferIdx = fCurrentBufferIdx = fBufferTopIdx;    
 
   // -- 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();
+  HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
 
   GetFirstBlk();
 
@@ -631,16 +684,21 @@ void AliHLTHOMERManager::AddBlockListToBuffer() {
     // -- Check sources list if block is requested
     if ( CheckIfRequested( block ) ) {
       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
+      fBlockList->Add(block);
     }
     else {
       // XXX HACK Jochen
       (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;
 }
 
@@ -652,46 +710,58 @@ void AliHLTHOMERManager::AddToAsyncBlockList() {
 
   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;
-    }
+
+    fAsyncBlockList->Add( block );
  
   } while( GetNextBlk() );
 
   return;
 }
-//##################################################################################
-TList* AliHLTHOMERManager::GetBlockListEventBuffer( Int_t idx ) {
+//__________________________________________________________________________________
+void AliHLTHOMERManager::AddToBlockList() {
   // see header file for class documentation
+  HLTInfo("Adding blocks to the synchroneous block list");
+
+  ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
+  
+  if ( fEventId == eventID ) {
+    HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
+    return;
+  }
 
-  if ( idx == -1 )
+  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;
 
-  return reinterpret_cast<TList*>((*fEventBuffer)[idx]);
 
 }
 
-/*
- * ---------------------------------------------------------------------------------
- *                          Block Handling - private
- * ---------------------------------------------------------------------------------
- */
 
-//##################################################################################
+//__________________________________________________________________________________
 Int_t AliHLTHOMERManager::HandleBlocks() {
   // see header file for class documentation
   
@@ -704,40 +774,24 @@ Int_t AliHLTHOMERManager::HandleBlocks() {
 
   // -- Check if blocks present
   if ( fNBlks ==  0 ) {
-    HLTWarning(Form("Event 0x%016LX (%Lu) with no blocks", eventID, eventID));
+    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
+  HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks));
     
-  // -- Check if blocks are from syncronous source
+  if ( IsSyncBlocks() ) {
+    //AddBlockListToBuffer();
+    fBlockList->Clear();
+    AddToBlockList();
+  } else {
+    AddToAsyncBlockList();
+  }
 
-   if ( IsSyncBlocks() )
-     AddBlockListToBuffer();
-   else
-     AddToAsyncBlockList();
-    
   return iResult;
 }
 
-//##################################################################################
+//__________________________________________________________________________________
 Bool_t AliHLTHOMERManager::IsSyncBlocks() {
   // see header file for class documentation
   
@@ -751,6 +805,11 @@ Bool_t AliHLTHOMERManager::IsSyncBlocks() {
       bResult = kTRUE;
       break;
     }
+
+    if ( !GetBlkType().CompareTo("GLOBTRIG")) {
+      bResult = kTRUE;
+      break;
+    }
     
     if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
       AliHLTHOMERBlockDesc blockDesc;
@@ -776,7 +835,7 @@ void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
   // Get pointer to current block in current event
    
   if ( !fCurrentReader || !IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+    HLTError("Not connected yet.");
     return NULL;
   }
   if ( ndx < static_cast<Int_t>(fNBlks) )
@@ -790,7 +849,7 @@ ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
   // see header file for class documentation
    
   if ( !fCurrentReader || !IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+    HLTError("Not connected yet.");
     return 0;
   }
   
@@ -808,7 +867,7 @@ TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
 
   // -- Check for Connection
   if ( !fCurrentReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+    HLTError("Not connected yet.");
     return origin;
   }
 
@@ -844,7 +903,7 @@ TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
 
   // -- Check for Connection
   if ( !fCurrentReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+    HLTError("Not connected yet.");
     return type;
   }
 
@@ -878,7 +937,7 @@ ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
 
   // -- Check for Connection
   if ( !fCurrentReader || ! IsConnected() ) {
-    HLTError(Form("Not connected yet."));
+    HLTError("Not connected yet.");
     return 0;
   }
 
@@ -940,8 +999,8 @@ Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
   Bool_t triggered = kFALSE;
 
   if ( !fCurrentReader || !IsConnected() ) {
-    HLTError(Form("Not connected yet."));
-    return NULL;
+    HLTError("Not connected yet.");
+    return kFALSE;
   }
 
   AliHLTHOMERBlockDesc blockDesc;
@@ -966,7 +1025,7 @@ Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
   } while( GetNextBlk() );
   
   if ( !foundTriggerBlock ) {
-    HLTError(Form("No trigger decision object found"));
+    HLTError("No trigger decision object found");
     return kFALSE;
   }