LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTHOMERManager.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 432 0.2 %
Date: 2016-06-14 17:26:59 Functions: 1 29 3.4 %

          Line data    Source code
       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         126 : ClassImp(AliHLTHOMERManager)
      46             : 
      47             : /*
      48             :  * ---------------------------------------------------------------------------------
      49             :  *                            Constructor / Destructor
      50             :  * ---------------------------------------------------------------------------------
      51             :  */
      52             : 
      53             : //##################################################################################
      54           0 :   AliHLTHOMERManager::AliHLTHOMERManager() :
      55           0 :   fLibManager(new AliHLTHOMERLibManager),
      56           0 :   fStateHasChanged(kTRUE),
      57           0 :   fProxyHandler(NULL),
      58           0 :   fCurrentReader(NULL),
      59           0 :   fReaderList(NULL),
      60           0 :   fSourceList(NULL),
      61           0 :   fNBlks(0),
      62           0 :   fEventID(),
      63           0 :   fEventId(-1),
      64           0 :   fCurrentBlk(0),
      65           0 :   fAsyncBlockList(NULL),
      66           0 :   fBlockList(NULL),
      67           0 :    fEventBuffer(NULL),
      68           0 :   fBufferTopIdx(-1),
      69           0 :   fBufferLowIdx(-1),
      70           0 :   fCurrentBufferIdx(-1),
      71           0 :   fNavigateBufferIdx(-1),
      72           0 :   fNEventsAvailable(0),
      73           0 :   fConnected(kFALSE), 
      74           0 :   fTriggerString("ALL"), 
      75           0 :   fNEventsNotTriggered(0),
      76           0 :   fRetryNextEvent(kFALSE),
      77           0 :   fIsBlockOwner(kTRUE)
      78           0 : {
      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           0 : }
      86             : 
      87             : //##################################################################################
      88           0 : AliHLTHOMERManager::~AliHLTHOMERManager() {
      89             :   // see header file for class documentation
      90             : 
      91           0 :   if ( fLibManager ) {
      92             : 
      93           0 :     if ( fReaderList ) {
      94           0 :       TIter next(fReaderList);
      95             :       TObject * object = NULL;
      96           0 :       while ( ( object = next()) )
      97           0 :         fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
      98             :       
      99           0 :       fReaderList->Clear();
     100           0 :       delete fReaderList;
     101           0 :     }
     102           0 :     fReaderList = NULL;   
     103             :     
     104           0 :     delete fLibManager;
     105             :   } 
     106           0 :   fLibManager = NULL;
     107             : 
     108           0 :   if ( fProxyHandler != NULL )
     109           0 :     delete fProxyHandler;
     110           0 :   fProxyHandler = NULL;
     111             : 
     112           0 :   if ( fSourceList != NULL )
     113           0 :     delete fSourceList;
     114           0 :   fSourceList = NULL;
     115             : 
     116           0 :   if ( fEventBuffer ) {
     117           0 :     fEventBuffer->Clear();
     118           0 :     delete fEventBuffer;
     119             :   }
     120           0 :   fEventBuffer = NULL;
     121             : 
     122           0 :   if(fBlockList) {
     123           0 :     fBlockList->Clear();
     124           0 :     delete fBlockList;
     125             :   }
     126           0 :   fBlockList = NULL;
     127             : 
     128           0 :   if ( fAsyncBlockList ) {
     129           0 :     fAsyncBlockList->Delete();
     130           0 :     delete fAsyncBlockList;
     131             :   }
     132           0 :   fAsyncBlockList = NULL;
     133           0 : }
     134             : 
     135             : //##################################################################################
     136             : Int_t AliHLTHOMERManager::Initialize() {
     137             :   // see header file for class documentation
     138             : 
     139           0 :   HLTInfo("Initializing");
     140             : 
     141             :   Int_t iResult = 0;
     142             : 
     143             :   // -- Initialize ProxyHandler
     144           0 :   if ( !fProxyHandler )
     145           0 :     fProxyHandler = new AliHLTHOMERProxyHandler();
     146             :   
     147           0 :   if ( fProxyHandler ) {
     148           0 :     iResult = fProxyHandler->Initialize();
     149           0 :     if (iResult)
     150           0 :       HLTError("Initialize of ProxyHandler failed.");
     151             :   
     152             :   } else {
     153             :     iResult = -1;
     154           0 :     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           0 :   if( !fReaderList )
     160           0 :     fReaderList = new TList();
     161             :   
     162             :   // -- Initialize asynchronous BlockList
     163           0 :   if( !fAsyncBlockList ) {
     164           0 :     fAsyncBlockList = new TList();
     165           0 :     fAsyncBlockList->SetOwner(kTRUE);
     166           0 :   }
     167             : 
     168             :   //initialize normal block list
     169           0 :   if( !fBlockList ) {
     170           0 :     fBlockList = new TList();
     171           0 :     fBlockList->SetOwner(kFALSE);
     172           0 :   }
     173             : 
     174             :   // -- Initialize Event Buffer and EventID array
     175           0 :   if ( !fEventBuffer ) {
     176           0 :     fEventBuffer = new TClonesArray( "TList", BUFFERSIZE );
     177           0 :   }
     178             : 
     179           0 :   for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) {
     180           0 :     new ((*fEventBuffer)[idx]) TList( );
     181           0 :     (reinterpret_cast<TList*>((*fEventBuffer)[idx]))->SetOwner(kTRUE);
     182             :     
     183           0 :     fEventID[idx] = 0;
     184             :   }
     185             : 
     186           0 :   return iResult;
     187           0 : }
     188             : 
     189             : /*
     190             :  * ---------------------------------------------------------------------------------
     191             :  *                                 Source Handling
     192             :  * ---------------------------------------------------------------------------------
     193             :  */
     194             : 
     195             : //##################################################################################
     196             : Int_t AliHLTHOMERManager::CreateSourcesList() {
     197             :   // see header file for class documentation
     198             : 
     199           0 :   if (fProxyHandler == NULL)
     200             :   {
     201           0 :     HLTError("The object must first be initialised with a call to Initialize().");
     202           0 :     return -1;
     203             :   }
     204             : 
     205             :   Int_t iResult = 0;
     206             : 
     207           0 :   if ( fSourceList != NULL )
     208           0 :     delete fSourceList;
     209           0 :   fSourceList = NULL;
     210             : 
     211           0 :   fSourceList = new TList();
     212           0 :   fSourceList->SetOwner( kTRUE );
     213             : 
     214           0 :   iResult = fProxyHandler->FillSourceList( fSourceList );
     215           0 :   if ( iResult < 0 ) {
     216           0 :     HLTWarning("There have been errors, while creating the sources list.");
     217             :   }
     218           0 :   else if ( iResult > 0 ) {
     219           0 :     HLTWarning("No active services found.");
     220             :   }
     221           0 :   else if ( fSourceList->IsEmpty() ) {
     222           0 :     HLTWarning("No active services in the list.");
     223             :     iResult = 2;
     224           0 :   }
     225             :   else {
     226           0 :      HLTInfo("New sources list created.");
     227             : 
     228             :     // -- New SourceList has been created 
     229             :     // --> All Sources are new --> State has changed
     230           0 :     fStateHasChanged = kTRUE;
     231             :   }
     232             : 
     233             :   return iResult;
     234           0 : }
     235             : 
     236             : //##################################################################################
     237             : void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) {
     238             :   // see header file for class documentation
     239             : 
     240           0 :   if ( source->IsSelected() != state ) {
     241           0 :     source->SetState( state );
     242           0 :     fStateHasChanged = kTRUE;
     243           0 :   }
     244             : 
     245           0 :   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           0 :   if (fReaderList == NULL or fSourceList == NULL)
     259             :   {
     260           0 :     HLTError("Must first create a source list with a call to CreateSourcesList().");
     261           0 :     return -1;
     262             :   }
     263             :   
     264             :   Int_t iResult = 0;
     265             : 
     266             :   // HAck Jochen
     267             :   //----
     268           0 :   detector="ALL";
     269             : 
     270             :   // -- Check if LibManager is present
     271           0 :   if ( ! fLibManager ) {
     272           0 :     HLTError("No LibManager present.");
     273           0 :     return -1;
     274             :   }
     275             :   
     276             :   // -- Check if already connected and state has not changed
     277           0 :   if ( fStateHasChanged == kFALSE && IsConnected() ) {
     278           0 :     HLTInfo("No need for reconnection.");
     279           0 :     return 0;
     280             :   }
     281             :   
     282             :   // -- If already connected, disconnect before connect
     283             :   //    or if ReaderList already filled
     284           0 :   if ( IsConnected() || fReaderList->GetSize() != 0 ) {
     285           0 :     HLTInfo(Form("IsConnected: %d      fReaderList.Size:   %d", IsConnected(), fReaderList->GetSize()));
     286           0 :     DisconnectHOMER();
     287           0 :   }
     288             :   // -- Create the Readoutlist
     289           0 :   UShort_t* sourcePorts = new UShort_t [fSourceList->GetEntries()];
     290           0 :   const Char_t ** sourceHostnames = new const Char_t* [fSourceList->GetEntries()];
     291           0 :   for(Int_t i = 0; i < fSourceList->GetEntries(); i++) {
     292           0 :    sourceHostnames[i] = "";
     293             :   }
     294           0 :   UInt_t sourceCount = 0;
     295             : 
     296           0 :   CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
     297           0 :   if ( sourceCount == 0 ) {
     298           0 :     HLTError("No sources selected, aborting.");
     299           0 :     delete [] sourcePorts;
     300           0 :     delete [] sourceHostnames;
     301           0 :     return -2;
     302             :   }
     303             : 
     304             :   // ***
     305             :   // *** Connect to data sources
     306             :   // ***
     307             :   
     308           0 :   for (UInt_t idx = 0; idx < sourceCount; idx++) {
     309             :     
     310           0 :     if (sourcePorts[idx] > 60000)
     311             :       continue;
     312             : 
     313           0 :     HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx]));
     314             :     
     315           0 :     fReaderList->Add(dynamic_cast<TObject*>(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx])));
     316           0 :     AliHLTHOMERReader *reader = static_cast<AliHLTHOMERReader*>(fReaderList->Last());
     317           0 :     if ( !reader ) {
     318           0 :       HLTError("Adding reader failed, aborting");
     319           0 :       delete [] sourcePorts;
     320           0 :       delete [] sourceHostnames;
     321           0 :       return -3;
     322             :     }
     323             : 
     324           0 :     if ( (iResult = reader->GetConnectionStatus()) )  {
     325             : 
     326             :       // -- Connection to source failed
     327             :       
     328           0 :       HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
     329             :                     sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
     330             : 
     331           0 :       if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) {
     332           0 :         HLTInfo("The failed connection is on localhost. is SSH tunnel up????? ");
     333           0 :         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           0 :       fReaderList->RemoveLast();
     339             : 
     340           0 :       if ( reader )
     341           0 :         fLibManager->DeleteReader( reader );
     342             :       reader = NULL;
     343             :       
     344           0 :       HLTInfo(Form("Removed source %d,  %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx]));
     345             :       
     346             :     } 
     347             :     else {
     348             :       // -- Connection succeded
     349           0 :       fConnected = kTRUE;
     350             : 
     351           0 :       HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx]));
     352             :     }
     353             :     
     354           0 :   } // for (Int_t idx = 0; idx < sourceCount; idx++) {
     355             :   
     356           0 :   delete[] sourceHostnames;
     357           0 :   delete[] sourcePorts;
     358             : 
     359           0 :   return iResult;
     360             : 
     361           0 : }
     362             : 
     363             : //##################################################################################
     364             : void AliHLTHOMERManager::DisconnectHOMER(){
     365             :   // see header file for class documentation
     366             : 
     367           0 :   HLTInfo("Disconnecting");
     368             : 
     369           0 :   if ( fReaderList && fLibManager ) {
     370           0 :     HLTInfo("Deleting readerlist and libmanager");
     371           0 :     TIter next(fReaderList);
     372             :     TObject * object = NULL;
     373           0 :     while ( ( object = next()) ) 
     374           0 :       fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
     375             :       
     376             : 
     377           0 :     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
     378           0 :     fReaderList->Clear();
     379           0 :     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
     380           0 :     delete fReaderList;
     381           0 :     fReaderList = new TList ();
     382           0 :     HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
     383           0 :   }
     384             :   
     385           0 :   fStateHasChanged = kTRUE;
     386           0 :   fConnected = kFALSE;
     387             :   
     388           0 :   HLTInfo("Connection closed.");
     389             : 
     390           0 :   return;
     391           0 : }
     392             : 
     393             : //##################################################################################
     394             : Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
     395             :   // see header file for class documentation
     396             :   
     397             :   Int_t iResult = 0;
     398             : 
     399           0 :   if ( IsConnected() )
     400           0 :     DisconnectHOMER();
     401             : 
     402           0 :   iResult = ConnectHOMER(detector);
     403           0 :   if ( iResult ) {
     404           0 :     HLTError("Error reconnecting.");
     405             :   }
     406             : 
     407           0 :   return iResult;
     408           0 : }
     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           0 :   if ( !IsConnected() || fStateHasChanged ) {
     425           0 :     HLTInfo("Not connected or state has changed, returning to AliEveHOMERManager, which will deal with this situation");
     426             :     //    cout << "connectecd  " << IsConnected()  << "haschanged  "<<fStateHasChanged << endl;
     427           0 :     return 55;//ConnectHOMER();
     428             :   }
     429           0 :   if ( !IsConnected() ) {
     430           0 :     HLTWarning("Not connected yet.");
     431           0 :     return -1;
     432             :   }
     433             : 
     434             :   // -- Reset asyncronous BlockList
     435           0 :   fAsyncBlockList->Delete();
     436             : 
     437             :   // ***
     438             :   // *** Loop over all readers and get new event data
     439             :   // ***
     440             :   
     441           0 :   TIter next(fReaderList);
     442             :   TObject * object = NULL;
     443             :   
     444           0 :   while( (object = next()) ) {
     445             :     
     446           0 :     fCurrentReader = static_cast<AliHLTHOMERReader*>(object);
     447             :     
     448             :     // -- Read next event data and error handling for HOMER (error codes and empty blocks)
     449           0 :     while ( 1 ) {
     450             :       
     451           0 :       iResult = fCurrentReader->ReadNextEvent( 40000000 /*timeout in us*/);
     452             :       
     453           0 :       if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
     454           0 :         HLTError(Form("No connection to source %d: %s (%d)", 
     455             :                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
     456             :         break;
     457             :       } 
     458           0 :       else if ( iResult == 110 ) {
     459           0 :         HLTError(Form("Timeout occured, reading event from source %d: %s (%d)", 
     460             :                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
     461             :         break;
     462             :       } 
     463           0 :       else if ( iResult == 56 ) {
     464           0 :         ++iRetryCount;
     465             :       
     466           0 :         if ( iRetryCount >= 20 ) {
     467           0 :           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           0 :           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           0 :       else if ( iResult ) {
     479           0 :         HLTError(Form("General Error reading event from source %d: %s (%d), giving up", 
     480             :                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
     481           0 :         fConnected = kFALSE;
     482           0 :         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           0 :     if ( iResult ) {
     493           0 :       HLTInfo("Reading event from source failed");
     494             :       continue;
     495             :     }
     496             : 
     497             :     // -- Handle Blocks from current reader
     498           0 :     iResult = HandleBlocks();
     499           0 :     if ( iResult ) {
     500           0 :       HLTError("Handling of blocks failed.");
     501             :     }
     502             : 
     503             :   } // while( (object = next()) ) {
     504             : 
     505             :   return iResult;  
     506           0 : }
     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           0 :   if ( fNavigateBufferIdx == fBufferLowIdx )
     519           0 :     return -1;
     520             : 
     521           0 :   Int_t newIdx = fNavigateBufferIdx - 1;
     522           0 :   if ( newIdx == -1 )
     523             :     newIdx = BUFFERSIZE-1;
     524             : 
     525           0 :   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
     526             : 
     527             :   return newIdx;
     528           0 : }
     529             : 
     530             : //##################################################################################
     531             : Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
     532             :   // see header file for class documentation
     533             : 
     534           0 :   HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
     535             : 
     536             :   // -- reached the top of the buffer
     537           0 :   if ( fNavigateBufferIdx == fBufferTopIdx )
     538           0 :     return -1;
     539             : 
     540           0 :   Int_t newIdx = fNavigateBufferIdx + 1;
     541           0 :   if ( newIdx == BUFFERSIZE )
     542             :     newIdx = 0;
     543             :   
     544           0 :   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
     545           0 :   fNEventsAvailable -= 1;
     546             : 
     547           0 :   HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
     548             : 
     549             : 
     550             :   return 0;
     551           0 : }
     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           0 :   TIter next( fSourceList );
     570           0 :   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
     571             : 
     572             :     ///Don't use sources from dev cluster
     573           0 :     if(source->GetPort() > 60000) continue;
     574             : 
     575             :     // -- If detector NO detector name given
     576           0 :     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           0 :       if ( detector.CompareTo(source->GetDetector()) )
     586             :         continue;
     587             :       else
     588           0 :         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           0 :     for ( UInt_t ii = 0; ii < sourceCount; ii++ ){
     595           0 :       if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) 
     596           0 :            && sourcePorts[ii] == source->GetPort() ) {
     597             :         exists = kTRUE;
     598           0 :         break;
     599             :       }
     600             :     }
     601             : 
     602             :     // -- Add new entires to readout list
     603           0 :     if ( ! exists ) {
     604           0 :       sourcePorts[sourceCount] = source->GetPort();
     605           0 :       sourceHostnames[sourceCount] = source->GetHostname().Data();
     606           0 :       sourceCount++;
     607           0 :     }
     608             : 
     609             :   } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
     610             : 
     611           0 :   fStateHasChanged = kFALSE;
     612             : 
     613             :   return;
     614           0 : }
     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           0 :   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
     627             :   
     628           0 :   if ( fEventID[fBufferTopIdx] == eventID ) {
     629           0 :     HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
     630           0 :     return;
     631             :   }
     632             : 
     633             :   // -- Check if event should be selected on basis of trigger string
     634           0 :   if( fTriggerString.CompareTo("ALL") ){
     635           0 :     if ( !CheckTriggerDecision() ) {
     636           0 :       HLTInfo("Event not triggered");
     637           0 :       return;
     638             :     } else {
     639           0 :       HLTInfo("Event triggered");
     640             :     }
     641             :   }
     642             :   else {
     643             :     HLTDebug("No trigger selection.");
     644             :   }
     645             : 
     646             :   // -- Set Top mark 
     647           0 :   ++fBufferTopIdx;
     648           0 :   if ( fBufferTopIdx == BUFFERSIZE )
     649           0 :     fBufferTopIdx = 0;
     650             : 
     651             :   // -- Change the low mark if necessary
     652           0 :   if ( fBufferLowIdx == -1 )
     653           0 :     fBufferLowIdx = 0;
     654           0 :   else if ( fBufferTopIdx == fBufferLowIdx ) {
     655           0 :     ++fBufferLowIdx;
     656           0 :     if ( fBufferLowIdx == BUFFERSIZE )
     657           0 :       fBufferLowIdx = 0;
     658             :   }
     659             : 
     660             : 
     661             :   // -- Fill EventID
     662           0 :   fEventID[fBufferTopIdx] = eventID;
     663             : 
     664             :   // -- Clear Buffer slot
     665           0 :   (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
     666           0 :   if(fBlockList->IsOwner()) HLTWarning("block list is owner!!");
     667           0 :   HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
     668             :   //fBlockList->Clear();
     669           0 :   fBlockList = new TList();
     670           0 :   HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
     671             : 
     672           0 :   GetFirstBlk();
     673             : 
     674             :   // -- Fill block list
     675           0 :   do {
     676             : 
     677             :     // -- Create new block
     678           0 :     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
     679           0 :     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
     680           0 :                      GetBlkType(), GetBlkSpecification() );
     681             :     
     682             :     // -- Check sources list if block is requested
     683           0 :     if ( CheckIfRequested( block ) ) {
     684           0 :       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
     685           0 :       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           0 :   } while( GetNextBlk() );
     696             : 
     697             :   //We have one more event available
     698           0 :   fNEventsAvailable++;
     699           0 :   HLTInfo(Form("fNEventsAvailable %d", fNEventsAvailable));
     700           0 :   return;
     701           0 : }
     702             : 
     703             : //##################################################################################
     704             : void AliHLTHOMERManager::AddToAsyncBlockList() {
     705             :   // see header file for class documentation
     706             : 
     707           0 :   HLTInfo("Adding blocks to the asynchroneous block list");
     708             : 
     709           0 :   GetFirstBlk();
     710             : 
     711           0 :   do {
     712             :     
     713           0 :     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
     714           0 :     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
     715           0 :                      GetBlkType(), GetBlkSpecification() );
     716             :     
     717             : 
     718           0 :     fAsyncBlockList->Add( block );
     719             :  
     720           0 :   } while( GetNextBlk() );
     721             : 
     722           0 :   return;
     723           0 : }
     724             : //__________________________________________________________________________________
     725             : void AliHLTHOMERManager::AddToBlockList() {
     726             :   // see header file for class documentation
     727           0 :   HLTInfo("Adding blocks to the synchroneous block list");
     728             : 
     729           0 :   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
     730             :   
     731           0 :   if ( fEventId == eventID ) {
     732           0 :     HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
     733           0 :     return;
     734             :   }
     735             : 
     736           0 :   fEventId = eventID;
     737             : 
     738           0 :   GetFirstBlk();
     739           0 :   do {
     740             : 
     741           0 :     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
     742           0 :     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
     743           0 :                      GetBlkType(), GetBlkSpecification() );
     744           0 :     fBlockList->Add( block );
     745             :   
     746           0 :   } while( GetNextBlk() );  
     747           0 : }
     748             : 
     749             : //__________________________________________________________________________________
     750             : TList* AliHLTHOMERManager::GetBlockListEventBuffer() {
     751             :   // see header file for class documentation
     752             : 
     753           0 :   if(fBlockList)
     754           0 :     return fBlockList;
     755             :   else 
     756           0 :     return NULL;
     757             : 
     758             : 
     759           0 : }
     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           0 :   fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt());
     770           0 :   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
     771           0 :   fCurrentBlk = 0;
     772             : 
     773             :   // -- Check if blocks present
     774           0 :   if ( fNBlks ==  0 ) {
     775           0 :     HLTWarning(Form("Event 0x%016lX (%lu) with no blocks", eventID, eventID));
     776           0 :     return -1;
     777             :   }
     778             : 
     779           0 :   HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks));
     780             :     
     781           0 :   if ( IsSyncBlocks() ) {
     782             :     //AddBlockListToBuffer();
     783           0 :     fBlockList->Clear();
     784           0 :     AddToBlockList();
     785           0 :   } else {
     786           0 :     AddToAsyncBlockList();
     787             :   }
     788             : 
     789           0 :   return iResult;
     790           0 : }
     791             : 
     792             : //__________________________________________________________________________________
     793             : Bool_t AliHLTHOMERManager::IsSyncBlocks() {
     794             :   // see header file for class documentation
     795             :   
     796             :   Bool_t bResult = kFALSE;
     797             : 
     798           0 :   GetFirstBlk();
     799             :   
     800           0 :   do {          
     801             :     
     802           0 :     if ( !GetBlkType().CompareTo("ALIESDV0")) {
     803             :       bResult = kTRUE;
     804           0 :       break;
     805             :     }
     806             : 
     807           0 :     if ( !GetBlkType().CompareTo("GLOBTRIG")) {
     808             :       bResult = kTRUE;
     809           0 :       break;
     810             :     }
     811             :     
     812           0 :     if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
     813           0 :       AliHLTHOMERBlockDesc blockDesc;
     814             :       
     815           0 :       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
     816           0 :                           GetBlkType(), GetBlkSpecification() );
     817           0 :       if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
     818             : 
     819             :         bResult = kTRUE;
     820           0 :         break;
     821             :       }
     822           0 :     }
     823             : 
     824           0 :   } while( GetNextBlk() );
     825             : 
     826             : 
     827           0 :   return bResult;
     828           0 : }
     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           0 :   if ( !fCurrentReader || !IsConnected() ) {
     836           0 :     HLTError("Not connected yet.");
     837           0 :     return NULL;
     838             :   }
     839           0 :   if ( ndx < static_cast<Int_t>(fNBlks) )
     840           0 :     return  const_cast<void*> (fCurrentReader->GetBlockData(ndx));
     841             :   else
     842           0 :     return NULL;
     843           0 : }
     844             : 
     845             : //##################################################################################
     846             : ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
     847             :   // see header file for class documentation
     848             :    
     849           0 :   if ( !fCurrentReader || !IsConnected() ) {
     850           0 :     HLTError("Not connected yet.");
     851           0 :     return 0;
     852             :   }
     853             :   
     854           0 :   if ( ndx < static_cast<Int_t>(fNBlks) )
     855           0 :     return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx));
     856             :   else
     857           0 :     return 0;
     858           0 : }
     859             : 
     860             : //##################################################################################
     861             : TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
     862             :   // see header file for class documentation
     863             : 
     864           0 :   TString origin = "";
     865             : 
     866             :   // -- Check for Connection
     867           0 :   if ( !fCurrentReader || ! IsConnected() ) {
     868           0 :     HLTError("Not connected yet.");
     869           0 :     return origin;
     870             :   }
     871             : 
     872             :   // -- Check block index
     873           0 :   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
     874           0 :     HLTError(Form("Block index %d out of range.", ndx ));
     875           0 :     return origin;
     876             :   }
     877             : 
     878             :   // -- Get origin
     879           0 :   union{
     880             :     UInt_t data;
     881             :     Char_t array[4];
     882             :   } reverseOrigin;
     883             : 
     884           0 :   reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx));
     885             : 
     886             :   // -- Reverse the order
     887           0 :   for (Int_t ii = 3; ii >= 0; ii-- )
     888           0 :     if ( reverseOrigin.array[ii] != ' ')
     889           0 :       origin.Append( reverseOrigin.array[ii] );
     890             : 
     891           0 :   origin.Remove( TString::kTrailing, ' ' );
     892             : 
     893             :   return origin;
     894           0 : }
     895             : 
     896             : //##################################################################################
     897             : TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
     898             :   // see header file for class documentation
     899             : 
     900           0 :   TString type = "";
     901             : 
     902             :   // -- Check for Connection
     903           0 :   if ( !fCurrentReader || ! IsConnected() ) {
     904           0 :     HLTError("Not connected yet.");
     905           0 :     return type;
     906             :   }
     907             : 
     908             :   // -- Check block index
     909           0 :   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
     910           0 :     HLTError(Form("Block index %d out of range.", ndx ));
     911           0 :     return type;
     912             :   }
     913             : 
     914             :   // -- Get type
     915           0 :   union{
     916             :     ULong64_t data;
     917             :     Char_t array[8];
     918             :   } reverseType;
     919             : 
     920           0 :   reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx));
     921             : 
     922             :   // -- Reverse the order
     923           0 :   for (Int_t ii = 7; ii >= 0; ii-- )
     924           0 :     if ( reverseType.array[ii] != ' ')
     925           0 :       type.Append( reverseType.array[ii] );
     926             :   
     927           0 :   type.Remove( TString::kTrailing, ' ' );
     928             : 
     929             :   return type;
     930           0 : }
     931             : 
     932             : //##################################################################################
     933             : ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
     934             :   // see header file for class documentation
     935             : 
     936             :   // -- Check for Connection
     937           0 :   if ( !fCurrentReader || ! IsConnected() ) {
     938           0 :     HLTError("Not connected yet.");
     939           0 :     return 0;
     940             :   }
     941             : 
     942             :   // -- Check block index
     943           0 :   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
     944           0 :     HLTError(Form("Block index %d out of range.", ndx ));
     945           0 :     return 0;
     946             :   }
     947             : 
     948           0 :   return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx));
     949           0 : }
     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           0 :   TIter next( fSourceList );
     961           0 :   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
     962             :     
     963             :     // -- Check if source is selected
     964           0 :     if ( ! source->IsSelected() )
     965             :       continue;
     966             :     
     967             :     // -- Check if detector matches
     968           0 :     if ( source->GetSourceName().CompareTo( block->GetBlockName() ) )
     969             :       continue;
     970             : 
     971             :     requested = kTRUE;
     972           0 :     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           0 :   return requested;
     986           0 : }
     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           0 :   if ( !fCurrentReader || !IsConnected() ) {
    1000           0 :     HLTError("Not connected yet.");
    1001           0 :     return kFALSE;
    1002             :   }
    1003             : 
    1004           0 :   AliHLTHOMERBlockDesc blockDesc;
    1005             : 
    1006           0 :   GetFirstBlk();
    1007             :   
    1008             :   // -- Fill block list
    1009             :   Bool_t foundTriggerBlock = kFALSE;
    1010             :   
    1011           0 :   do {
    1012           0 :     if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) {
    1013           0 :       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
    1014           0 :                           GetBlkType(), GetBlkSpecification() );
    1015             : 
    1016           0 :       if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
    1017             : 
    1018             :         foundTriggerBlock = kTRUE;
    1019           0 :         break;
    1020             :       }
    1021             :       
    1022             :     }
    1023           0 :   } while( GetNextBlk() );
    1024             :   
    1025           0 :   if ( !foundTriggerBlock ) {
    1026           0 :     HLTError("No trigger decision object found");
    1027           0 :     return kFALSE;
    1028             :   }
    1029             : 
    1030             :   // -- Get the global decision object
    1031             :   AliHLTGlobalTriggerDecision* globalDecision = 
    1032           0 :     static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject());
    1033             : 
    1034           0 :   if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) {
    1035           0 :     triggered = globalDecision->EventTriggered();
    1036           0 :   } 
    1037             :   else {
    1038             :     
    1039           0 :     for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
    1040             :        
    1041             :       const AliHLTTriggerDecision* triggerDecision = 
    1042           0 :         reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx));
    1043             :     
    1044           0 :       if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) {
    1045           0 :         triggered = triggerDecision->EventTriggered();
    1046           0 :         break;
    1047             :       }
    1048           0 :     } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
    1049             :   }
    1050             : 
    1051             : 
    1052             : 
    1053           0 :   if ( triggered ) {
    1054           0 :     fRetryNextEvent = kFALSE;
    1055           0 :     fNEventsNotTriggered = 0;
    1056           0 :   }
    1057             :   else {
    1058           0 :     fRetryNextEvent = kTRUE;
    1059           0 :     ++fNEventsNotTriggered;
    1060             :   }
    1061             : 
    1062             :   return triggered;
    1063           0 : }

Generated by: LCOV version 1.11