From: jthaeder Date: Mon, 30 Nov 2009 20:22:16 +0000 (+0000) Subject: changed back to unix style X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=1ad3c9f40e7aab5718d4226d16f33154bd541ffe changed back to unix style --- diff --git a/HLT/BASE/AliHLTHOMERManager.cxx b/HLT/BASE/AliHLTHOMERManager.cxx index a175ae36257..cf6c30360e0 100644 --- a/HLT/BASE/AliHLTHOMERManager.cxx +++ b/HLT/BASE/AliHLTHOMERManager.cxx @@ -1,1011 +1,1011 @@ -//-*- Mode: C++ -*- -// $Id: AliHLTHOMERManager.cxx $ -//************************************************************************** -//* This file is property of and copyright by the ALICE HLT Project * -//* ALICE Experiment at CERN, All rights reserved. * -//* * -//* Primary Authors: Jochen Thaeder * -//* for The ALICE HLT Project. * -//* * -//* Permission to use, copy, modify and distribute this software and its * -//* documentation strictly for non-commercial purposes is hereby granted * -//* without fee, provided that the above copyright notice appears in all * -//* copies and that both the copyright notice and this permission notice * -//* appear in the supporting documentation. The authors make no claims * -//* about the suitability of this software for any purpose. It is * -//* provided "as is" without express or implied warranty. * -//************************************************************************** - -/** @file AliHLTHOMERManager.cxx - @author Jochen Thaeder - @date - @brief Manger for HOMER in aliroot -*/ - -// see header file for class documentation -// or -// refer to README to build package -// or -// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt - -#if __GNUC__>= 3 - using namespace std; -#endif - -#define EVE_DEBUG 0 - -#include "AliHLTHOMERManager.h" -// -- -- -- -- -- -- -- -#include "AliHLTHOMERLibManager.h" -#include "AliHLTHOMERSourceDesc.h" -#include "AliHLTHOMERBlockDesc.h" -// -- -- -- -- -- -- -- -#include "AliHLTGlobalTriggerDecision.h" -#include "AliHLTTriggerDecision.h" -//--------------------------- - -ClassImp(AliHLTHOMERManager) - -/* - * --------------------------------------------------------------------------------- - * Constructor / Destructor - * --------------------------------------------------------------------------------- - */ - -//################################################################################## - AliHLTHOMERManager::AliHLTHOMERManager() : - fLibManager(new AliHLTHOMERLibManager), - fStateHasChanged(kTRUE), - fProxyHandler(NULL), - fCurrentReader(NULL), - fReaderList(NULL), - fSourceList(NULL), - fNBlks(0), - fEventID(), - fCurrentBlk(0), - 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 - // or - // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt - -} - -//################################################################################## -AliHLTHOMERManager::~AliHLTHOMERManager() { - // see header file for class documentation - - if ( fLibManager ) { - - if ( fReaderList ) { - TIter next(fReaderList); - TObject * object = NULL; - while ( ( object = next()) ) - fLibManager->DeleteReader(static_cast(object) ); - - fReaderList->Clear(); - delete fReaderList; - } - fReaderList = NULL; - - delete fLibManager; - } - fLibManager = NULL; - - if ( fProxyHandler != NULL ) - delete fProxyHandler; - fProxyHandler = NULL; - - if ( fSourceList != NULL ) - delete fSourceList; - fSourceList = NULL; - - if ( fEventBuffer ) { - fEventBuffer->Clear(); - delete fEventBuffer; - } - fEventBuffer = NULL; - - if ( fAsyncBlockList ) { - fAsyncBlockList->Clear(); - delete fAsyncBlockList; - } - fAsyncBlockList = NULL; -} - -//################################################################################## -Int_t AliHLTHOMERManager::Initialize() { - // see header file for class documentation - - Int_t iResult = 0; - - // -- Initialize ProxyHandler - if ( !fProxyHandler ) - fProxyHandler = new AliHLTHOMERProxyHandler(); - - if ( fProxyHandler ) { - iResult = fProxyHandler->Initialize(); - if (iResult) - HLTError(Form("Initialize of ProxyHandler failed.")); - } - else { - iResult = -1; - 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(kFALSE); - } - - // -- Initialize Event Buffer and EventID array - if ( !fEventBuffer ) { - fEventBuffer = new TClonesArray( "TList", BUFFERSIZE ); - } - - for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) { - new ((*fEventBuffer)[idx]) TList( ); - (reinterpret_cast((*fEventBuffer)[idx]))->SetOwner(kTRUE); - - fEventID[idx] = 0; - } - - return iResult; -} - -/* - * --------------------------------------------------------------------------------- - * Source Handling - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -Int_t AliHLTHOMERManager::CreateSourcesList() { - // see header file for class documentation - - Int_t iResult = 0; - - if ( fSourceList != NULL ) - delete fSourceList; - fSourceList = NULL; - - fSourceList = new TList(); - fSourceList->SetOwner( kTRUE ); - - iResult = fProxyHandler->FillSourceList( fSourceList ); - if ( iResult < 0 ) { - HLTWarning(Form("There have been errors, while creating the sources list.")); - } - 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.")); - - // -- New SourceList has been created - // --> All Sources are new --> State has changed - fStateHasChanged = kTRUE; - } - - return iResult; -} - -//################################################################################## -void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) { - // see header file for class documentation - - if ( source->IsSelected() != state ) { - source->SetState( state ); - fStateHasChanged = kTRUE; - } - - return; -} - -/* - * --------------------------------------------------------------------------------- - * Connection Handling - public - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){ - // see header file for class documentation - - Int_t iResult = 0; - - // -- 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 0; - } - - // -- If already connected, disconnect before connect - // or if ReaderList already filled - if ( IsConnected() || fReaderList->GetSize() != 0 ) - DisconnectHOMER(); - - // -- Create the Readoutlist - UShort_t* sourcePorts = new UShort_t [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 -2; - } - - // *** - // *** Connect to data sources - // *** - - for (UInt_t idx = 0; idx < sourceCount; idx++) { - - HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx])); - - fReaderList->Add(dynamic_cast(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx]))); - AliHLTHOMERReader *reader = static_cast(fReaderList->Last()); - if ( !reader ) { - HLTError(Form("Adding reader failed, aborting")); - return -3; - } - - if ( (iResult = reader->GetConnectionStatus()) ) { - - // -- Connection to source failed - - HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)", - sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult)); - - if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) { - HLTInfo("The failed connection is on localhost. is SSH tunnel up????? "); - HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'", - sourcePorts[idx], sourcePorts[idx])); - } - - // -- Remove reader - fReaderList->RemoveLast(); - - if ( reader ) - fLibManager->DeleteReader( reader ); - reader = NULL; - - HLTInfo(Form("Removed source %d, %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx])); - - } - else { - // -- Connection succeded - fConnected = kTRUE; - - HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx])); - } - - } // for (Int_t idx = 0; idx < sourceCount; idx++) { - - delete[] sourceHostnames; - delete[] sourcePorts; - - return iResult; - -} - -//################################################################################## -void AliHLTHOMERManager::DisconnectHOMER(){ - // see header file for class documentation - - if ( ! IsConnected() ) - return; - - if ( fReaderList && fLibManager ) { - TIter next(fReaderList); - TObject * object = NULL; - while ( ( object = next()) ) - fLibManager->DeleteReader(static_cast(object) ); - - fReaderList->Clear(); - delete fReaderList; - fReaderList = NULL; - } - - fStateHasChanged = kTRUE; - fConnected = kFALSE; - - HLTInfo(Form("Connection closed.")); - - return; -} - -//################################################################################## -Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){ - // see header file for class documentation - - Int_t iResult = 0; - - if ( IsConnected() ) - DisconnectHOMER(); - - iResult = ConnectHOMER(detector); - if ( iResult ) { - HLTError(Form("Error reconnecting.")); - } - - return iResult; -} - -/* - * --------------------------------------------------------------------------------- - * Event Handling - public - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -Int_t AliHLTHOMERManager::NextEvent(){ - - // see header file for class documentation - - - Int_t iResult = 0; - Int_t iRetryCount = 0; - - if ( !IsConnected() || fStateHasChanged ) - ConnectHOMER(); - - if ( !IsConnected() ) { - HLTWarning(Form( "Not connected yet." )); - return -1; - } - - // -- Reset asyncronous BlockList - fAsyncBlockList->Clear(); - - // *** - // *** Loop over all readers and get new event data - // *** - - TIter next(fReaderList); - TObject * object = NULL; - - while( (object = next()) ) { - - fCurrentReader = static_cast(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 { - break; - } - - } // while( 1 ) { - - - // -- Check if event could be read - if ( iResult ) - continue; - - // -- Handle Blocks from current reader - iResult = HandleBlocks(); - if ( iResult ) { - HLTError(Form("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; -} - -/* --------------------------------------------------------------------------------- - * Buffer Handling - public - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -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 - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts, - UInt_t &sourceCount, TString detector ){ - // see header file for class documentation - - AliHLTHOMERSourceDesc * source= NULL; - - // -- Read all sources and check if they should be read out - TIter next( fSourceList ); - while ( ( source = dynamic_cast(next()) ) ) { - - // -- If detector NO detector name given - if ( ! detector.CompareTo("ALL") ) { - // -- Continue if source is not selected - if ( ! source->IsSelected() ) - continue; - } - // -- DetectorName given - else { - // -- Continue if detector name doesn't match - if ( detector.CompareTo(source->GetDetector()) ) - continue; - else - source->Select(); - } - - Bool_t exists = kFALSE; - - // -- Loop over existing entries and check if entry is already in readout list - for ( UInt_t ii = 0; ii < sourceCount; ii++ ){ - if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) - && sourcePorts[ii] == source->GetPort() ) { - exists = kTRUE; - break; - } - } - - // -- Add new entires to readout list - if ( ! exists ) { - sourcePorts[sourceCount] = source->GetPort(); - sourceHostnames[sourceCount] = source->GetHostname().Data(); - sourceCount++; - } - - } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) { - - fStateHasChanged = kFALSE; - - return; -} - -/* - * --------------------------------------------------------------------------------- - * Buffer Handling - private - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -void AliHLTHOMERManager::AddBlockListToBuffer() { - // see header file for class documentation - - // -- Check if event is already in buffer - ULong_t eventID = static_cast(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(Form("Event 0x%016LX (%Lu) is not triggered by %s.", - eventID, eventID, fTriggerString.Data())); - return; - } - } - else { - HLTInfo("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; - - // -- Fill EventID - fEventID[fBufferTopIdx] = eventID; - - // -- Clear Buffer slot - (reinterpret_cast((*fEventBuffer)[fBufferTopIdx]))->Clear(); - - - 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 ) ) { - (reinterpret_cast((*fEventBuffer)[fBufferTopIdx]))->Add( block ); - } - else { - // XXX HACK Jochen - (reinterpret_cast((*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((*fEventBuffer)[idx]); - -} - -/* - * --------------------------------------------------------------------------------- - * Block Handling - private - * --------------------------------------------------------------------------------- - */ - -//################################################################################## -Int_t AliHLTHOMERManager::HandleBlocks() { - // see header file for class documentation - - Int_t iResult = 0; - - // -- Get blockCnt and eventID - fNBlks = static_cast(fCurrentReader->GetBlockCnt()); - ULong_t eventID = static_cast(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 1// 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(tmp11); - *tmp12 = fCurrentReader->GetBlockDataType(ii); - void *tmp21 = tmp2; - ULong_t* tmp22 = static_cast(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") || - - if ( !GetBlkType().CompareTo("ALIESDV0") || - !GetBlkType().CompareTo("CLUSTERS") ) { - - 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 ( !fCurrentReader || !IsConnected() ) { - HLTError(Form("Not connected yet.")); - return NULL; - } - if ( ndx < static_cast(fNBlks) ) - return const_cast (fCurrentReader->GetBlockData(ndx)); - else - return NULL; -} - -//################################################################################## -ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) { - // see header file for class documentation - - if ( !fCurrentReader || !IsConnected() ) { - HLTError(Form("Not connected yet.")); - return 0; - } - - if ( ndx < static_cast(fNBlks) ) - return static_cast (fCurrentReader->GetBlockDataLength(ndx)); - else - return 0; -} - -//################################################################################## -TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) { - // see header file for class documentation - - TString origin = ""; - - // -- Check for Connection - if ( !fCurrentReader || ! IsConnected() ) { - HLTError(Form("Not connected yet.")); - return origin; - } - - // -- Check block index - if ( ndx >= static_cast(fNBlks) ) { - HLTError(Form("Block index %d out of range.", ndx )); - return origin; - } - - // -- Get origin - union{ - UInt_t data; - Char_t array[4]; - } reverseOrigin; - - reverseOrigin.data = static_cast(fCurrentReader->GetBlockDataOrigin(ndx)); - - // -- Reverse the order - for (Int_t ii = 3; ii >= 0; ii-- ) - if ( reverseOrigin.array[ii] != ' ') - origin.Append( reverseOrigin.array[ii] ); - - origin.Remove( TString::kTrailing, ' ' ); - - return origin; -} - -//################################################################################## -TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) { - // see header file for class documentation - - TString type = ""; - - // -- Check for Connection - if ( !fCurrentReader || ! IsConnected() ) { - HLTError(Form("Not connected yet.")); - return type; - } - - // -- Check block index - if ( ndx >= static_cast(fNBlks) ) { - HLTError(Form("Block index %d out of range.", ndx )); - return type; - } - - // -- Get type - union{ - ULong64_t data; - Char_t array[8]; - } reverseType; - - reverseType.data = static_cast (fCurrentReader->GetBlockDataType(ndx)); - - // -- Reverse the order - for (Int_t ii = 7; ii >= 0; ii-- ) - if ( reverseType.array[ii] != ' ') - type.Append( reverseType.array[ii] ); - - type.Remove( TString::kTrailing, ' ' ); - - return type; -} - -//################################################################################## -ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) { - // see header file for class documentation - - // -- Check for Connection - if ( !fCurrentReader || ! IsConnected() ) { - HLTError(Form("Not connected yet.")); - return 0; - } - - // -- Check block index - if ( ndx >= static_cast(fNBlks) ) { - HLTError(Form("Block index %d out of range.", ndx )); - return 0; - } - - return static_cast(fCurrentReader->GetBlockDataSpec(ndx)); -} - -//################################################################################## -Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) { - // see header file for class documentation - - Bool_t requested = kFALSE; - - AliHLTHOMERSourceDesc * source= NULL; - - // -- Read all sources and check if they should be read out - TIter next( fSourceList ); - while ( ( source = dynamic_cast(next()) ) ) { - - // -- Check if source is selected - if ( ! source->IsSelected() ) - continue; - - // -- Check if detector matches - if ( source->GetSourceName().CompareTo( block->GetBlockName() ) ) - continue; - - requested = kTRUE; - break; - - } // while ( ( source = dynamic_cast(next()) ) ) { - -#if EVE_DEBUG - if ( requested ) { - HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); - } - else { - HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data())); - } -#endif - - 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 NULL; - } - - 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(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(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; -} +//-*- Mode: C++ -*- +// $Id: AliHLTHOMERManager.cxx $ +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Jochen Thaeder * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/** @file AliHLTHOMERManager.cxx + @author Jochen Thaeder + @date + @brief Manger for HOMER in aliroot +*/ + +// see header file for class documentation +// or +// refer to README to build package +// or +// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + +#if __GNUC__>= 3 + using namespace std; +#endif + +#define EVE_DEBUG 0 + +#include "AliHLTHOMERManager.h" +// -- -- -- -- -- -- -- +#include "AliHLTHOMERLibManager.h" +#include "AliHLTHOMERSourceDesc.h" +#include "AliHLTHOMERBlockDesc.h" +// -- -- -- -- -- -- -- +#include "AliHLTGlobalTriggerDecision.h" +#include "AliHLTTriggerDecision.h" +//--------------------------- + +ClassImp(AliHLTHOMERManager) + +/* + * --------------------------------------------------------------------------------- + * Constructor / Destructor + * --------------------------------------------------------------------------------- + */ + +//################################################################################## + AliHLTHOMERManager::AliHLTHOMERManager() : + fLibManager(new AliHLTHOMERLibManager), + fStateHasChanged(kTRUE), + fProxyHandler(NULL), + fCurrentReader(NULL), + fReaderList(NULL), + fSourceList(NULL), + fNBlks(0), + fEventID(), + fCurrentBlk(0), + 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 + // or + // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + +} + +//################################################################################## +AliHLTHOMERManager::~AliHLTHOMERManager() { + // see header file for class documentation + + if ( fLibManager ) { + + if ( fReaderList ) { + TIter next(fReaderList); + TObject * object = NULL; + while ( ( object = next()) ) + fLibManager->DeleteReader(static_cast(object) ); + + fReaderList->Clear(); + delete fReaderList; + } + fReaderList = NULL; + + delete fLibManager; + } + fLibManager = NULL; + + if ( fProxyHandler != NULL ) + delete fProxyHandler; + fProxyHandler = NULL; + + if ( fSourceList != NULL ) + delete fSourceList; + fSourceList = NULL; + + if ( fEventBuffer ) { + fEventBuffer->Clear(); + delete fEventBuffer; + } + fEventBuffer = NULL; + + if ( fAsyncBlockList ) { + fAsyncBlockList->Clear(); + delete fAsyncBlockList; + } + fAsyncBlockList = NULL; +} + +//################################################################################## +Int_t AliHLTHOMERManager::Initialize() { + // see header file for class documentation + + Int_t iResult = 0; + + // -- Initialize ProxyHandler + if ( !fProxyHandler ) + fProxyHandler = new AliHLTHOMERProxyHandler(); + + if ( fProxyHandler ) { + iResult = fProxyHandler->Initialize(); + if (iResult) + HLTError(Form("Initialize of ProxyHandler failed.")); + } + else { + iResult = -1; + 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(kFALSE); + } + + // -- Initialize Event Buffer and EventID array + if ( !fEventBuffer ) { + fEventBuffer = new TClonesArray( "TList", BUFFERSIZE ); + } + + for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) { + new ((*fEventBuffer)[idx]) TList( ); + (reinterpret_cast((*fEventBuffer)[idx]))->SetOwner(kTRUE); + + fEventID[idx] = 0; + } + + return iResult; +} + +/* + * --------------------------------------------------------------------------------- + * Source Handling + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +Int_t AliHLTHOMERManager::CreateSourcesList() { + // see header file for class documentation + + Int_t iResult = 0; + + if ( fSourceList != NULL ) + delete fSourceList; + fSourceList = NULL; + + fSourceList = new TList(); + fSourceList->SetOwner( kTRUE ); + + iResult = fProxyHandler->FillSourceList( fSourceList ); + if ( iResult < 0 ) { + HLTWarning(Form("There have been errors, while creating the sources list.")); + } + 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.")); + + // -- New SourceList has been created + // --> All Sources are new --> State has changed + fStateHasChanged = kTRUE; + } + + return iResult; +} + +//################################################################################## +void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) { + // see header file for class documentation + + if ( source->IsSelected() != state ) { + source->SetState( state ); + fStateHasChanged = kTRUE; + } + + return; +} + +/* + * --------------------------------------------------------------------------------- + * Connection Handling - public + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){ + // see header file for class documentation + + Int_t iResult = 0; + + // -- 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 0; + } + + // -- If already connected, disconnect before connect + // or if ReaderList already filled + if ( IsConnected() || fReaderList->GetSize() != 0 ) + DisconnectHOMER(); + + // -- Create the Readoutlist + UShort_t* sourcePorts = new UShort_t [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 -2; + } + + // *** + // *** Connect to data sources + // *** + + for (UInt_t idx = 0; idx < sourceCount; idx++) { + + HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx])); + + fReaderList->Add(dynamic_cast(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx]))); + AliHLTHOMERReader *reader = static_cast(fReaderList->Last()); + if ( !reader ) { + HLTError(Form("Adding reader failed, aborting")); + return -3; + } + + if ( (iResult = reader->GetConnectionStatus()) ) { + + // -- Connection to source failed + + HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)", + sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult)); + + if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) { + HLTInfo("The failed connection is on localhost. is SSH tunnel up????? "); + HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'", + sourcePorts[idx], sourcePorts[idx])); + } + + // -- Remove reader + fReaderList->RemoveLast(); + + if ( reader ) + fLibManager->DeleteReader( reader ); + reader = NULL; + + HLTInfo(Form("Removed source %d, %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx])); + + } + else { + // -- Connection succeded + fConnected = kTRUE; + + HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx])); + } + + } // for (Int_t idx = 0; idx < sourceCount; idx++) { + + delete[] sourceHostnames; + delete[] sourcePorts; + + return iResult; + +} + +//################################################################################## +void AliHLTHOMERManager::DisconnectHOMER(){ + // see header file for class documentation + + if ( ! IsConnected() ) + return; + + if ( fReaderList && fLibManager ) { + TIter next(fReaderList); + TObject * object = NULL; + while ( ( object = next()) ) + fLibManager->DeleteReader(static_cast(object) ); + + fReaderList->Clear(); + delete fReaderList; + fReaderList = NULL; + } + + fStateHasChanged = kTRUE; + fConnected = kFALSE; + + HLTInfo(Form("Connection closed.")); + + return; +} + +//################################################################################## +Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){ + // see header file for class documentation + + Int_t iResult = 0; + + if ( IsConnected() ) + DisconnectHOMER(); + + iResult = ConnectHOMER(detector); + if ( iResult ) { + HLTError(Form("Error reconnecting.")); + } + + return iResult; +} + +/* + * --------------------------------------------------------------------------------- + * Event Handling - public + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +Int_t AliHLTHOMERManager::NextEvent(){ + + // see header file for class documentation + + + Int_t iResult = 0; + Int_t iRetryCount = 0; + + if ( !IsConnected() || fStateHasChanged ) + ConnectHOMER(); + + if ( !IsConnected() ) { + HLTWarning(Form( "Not connected yet." )); + return -1; + } + + // -- Reset asyncronous BlockList + fAsyncBlockList->Clear(); + + // *** + // *** Loop over all readers and get new event data + // *** + + TIter next(fReaderList); + TObject * object = NULL; + + while( (object = next()) ) { + + fCurrentReader = static_cast(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 { + break; + } + + } // while( 1 ) { + + + // -- Check if event could be read + if ( iResult ) + continue; + + // -- Handle Blocks from current reader + iResult = HandleBlocks(); + if ( iResult ) { + HLTError(Form("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; +} + +/* --------------------------------------------------------------------------------- + * Buffer Handling - public + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +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 + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts, + UInt_t &sourceCount, TString detector ){ + // see header file for class documentation + + AliHLTHOMERSourceDesc * source= NULL; + + // -- Read all sources and check if they should be read out + TIter next( fSourceList ); + while ( ( source = dynamic_cast(next()) ) ) { + + // -- If detector NO detector name given + if ( ! detector.CompareTo("ALL") ) { + // -- Continue if source is not selected + if ( ! source->IsSelected() ) + continue; + } + // -- DetectorName given + else { + // -- Continue if detector name doesn't match + if ( detector.CompareTo(source->GetDetector()) ) + continue; + else + source->Select(); + } + + Bool_t exists = kFALSE; + + // -- Loop over existing entries and check if entry is already in readout list + for ( UInt_t ii = 0; ii < sourceCount; ii++ ){ + if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) + && sourcePorts[ii] == source->GetPort() ) { + exists = kTRUE; + break; + } + } + + // -- Add new entires to readout list + if ( ! exists ) { + sourcePorts[sourceCount] = source->GetPort(); + sourceHostnames[sourceCount] = source->GetHostname().Data(); + sourceCount++; + } + + } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) { + + fStateHasChanged = kFALSE; + + return; +} + +/* + * --------------------------------------------------------------------------------- + * Buffer Handling - private + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +void AliHLTHOMERManager::AddBlockListToBuffer() { + // see header file for class documentation + + // -- Check if event is already in buffer + ULong_t eventID = static_cast(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(Form("Event 0x%016LX (%Lu) is not triggered by %s.", + eventID, eventID, fTriggerString.Data())); + return; + } + } + else { + HLTInfo("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; + + // -- Fill EventID + fEventID[fBufferTopIdx] = eventID; + + // -- Clear Buffer slot + (reinterpret_cast((*fEventBuffer)[fBufferTopIdx]))->Clear(); + + + 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 ) ) { + (reinterpret_cast((*fEventBuffer)[fBufferTopIdx]))->Add( block ); + } + else { + // XXX HACK Jochen + (reinterpret_cast((*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((*fEventBuffer)[idx]); + +} + +/* + * --------------------------------------------------------------------------------- + * Block Handling - private + * --------------------------------------------------------------------------------- + */ + +//################################################################################## +Int_t AliHLTHOMERManager::HandleBlocks() { + // see header file for class documentation + + Int_t iResult = 0; + + // -- Get blockCnt and eventID + fNBlks = static_cast(fCurrentReader->GetBlockCnt()); + ULong_t eventID = static_cast(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 1// 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(tmp11); + *tmp12 = fCurrentReader->GetBlockDataType(ii); + void *tmp21 = tmp2; + ULong_t* tmp22 = static_cast(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") || + + if ( !GetBlkType().CompareTo("ALIESDV0") || + !GetBlkType().CompareTo("CLUSTERS") ) { + + 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 ( !fCurrentReader || !IsConnected() ) { + HLTError(Form("Not connected yet.")); + return NULL; + } + if ( ndx < static_cast(fNBlks) ) + return const_cast (fCurrentReader->GetBlockData(ndx)); + else + return NULL; +} + +//################################################################################## +ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) { + // see header file for class documentation + + if ( !fCurrentReader || !IsConnected() ) { + HLTError(Form("Not connected yet.")); + return 0; + } + + if ( ndx < static_cast(fNBlks) ) + return static_cast (fCurrentReader->GetBlockDataLength(ndx)); + else + return 0; +} + +//################################################################################## +TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) { + // see header file for class documentation + + TString origin = ""; + + // -- Check for Connection + if ( !fCurrentReader || ! IsConnected() ) { + HLTError(Form("Not connected yet.")); + return origin; + } + + // -- Check block index + if ( ndx >= static_cast(fNBlks) ) { + HLTError(Form("Block index %d out of range.", ndx )); + return origin; + } + + // -- Get origin + union{ + UInt_t data; + Char_t array[4]; + } reverseOrigin; + + reverseOrigin.data = static_cast(fCurrentReader->GetBlockDataOrigin(ndx)); + + // -- Reverse the order + for (Int_t ii = 3; ii >= 0; ii-- ) + if ( reverseOrigin.array[ii] != ' ') + origin.Append( reverseOrigin.array[ii] ); + + origin.Remove( TString::kTrailing, ' ' ); + + return origin; +} + +//################################################################################## +TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) { + // see header file for class documentation + + TString type = ""; + + // -- Check for Connection + if ( !fCurrentReader || ! IsConnected() ) { + HLTError(Form("Not connected yet.")); + return type; + } + + // -- Check block index + if ( ndx >= static_cast(fNBlks) ) { + HLTError(Form("Block index %d out of range.", ndx )); + return type; + } + + // -- Get type + union{ + ULong64_t data; + Char_t array[8]; + } reverseType; + + reverseType.data = static_cast (fCurrentReader->GetBlockDataType(ndx)); + + // -- Reverse the order + for (Int_t ii = 7; ii >= 0; ii-- ) + if ( reverseType.array[ii] != ' ') + type.Append( reverseType.array[ii] ); + + type.Remove( TString::kTrailing, ' ' ); + + return type; +} + +//################################################################################## +ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) { + // see header file for class documentation + + // -- Check for Connection + if ( !fCurrentReader || ! IsConnected() ) { + HLTError(Form("Not connected yet.")); + return 0; + } + + // -- Check block index + if ( ndx >= static_cast(fNBlks) ) { + HLTError(Form("Block index %d out of range.", ndx )); + return 0; + } + + return static_cast(fCurrentReader->GetBlockDataSpec(ndx)); +} + +//################################################################################## +Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) { + // see header file for class documentation + + Bool_t requested = kFALSE; + + AliHLTHOMERSourceDesc * source= NULL; + + // -- Read all sources and check if they should be read out + TIter next( fSourceList ); + while ( ( source = dynamic_cast(next()) ) ) { + + // -- Check if source is selected + if ( ! source->IsSelected() ) + continue; + + // -- Check if detector matches + if ( source->GetSourceName().CompareTo( block->GetBlockName() ) ) + continue; + + requested = kTRUE; + break; + + } // while ( ( source = dynamic_cast(next()) ) ) { + +#if EVE_DEBUG + if ( requested ) { + HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); + } + else { + HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data())); + } +#endif + + 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 NULL; + } + + 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(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(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; +} diff --git a/HLT/BASE/AliHLTHOMERManager.h b/HLT/BASE/AliHLTHOMERManager.h index 3823bfd525f..fad0d49f1b4 100644 --- a/HLT/BASE/AliHLTHOMERManager.h +++ b/HLT/BASE/AliHLTHOMERManager.h @@ -1,404 +1,404 @@ -//-*- Mode: C++ -*- - -// $Id: AliHLTHOMERManager.h $ - -#ifndef ALIHLTHOMERMANAGER_H -#define ALIHLTHOMERMANAGER_H - -/* This file is property of and copyright by the ALICE HLT Project * - * ALICE Experiment at CERN, All rights reserved. * - * See cxx source for full Copyright notice - */ - -/** @file AliHLTHOMERManager.h - @author Jochen Thaeder - @date - @brief Manager for HOMER in aliroot -*/ - - -#include "TClonesArray.h" -#include "TString.h" -#include "TList.h" - -#include "AliHLTHOMERSourceDesc.h" -#include "AliHLTHOMERBlockDesc.h" -#include "AliHLTHOMERReader.h" -#include "AliHLTHOMERProxyHandler.h" - -#include "AliHLTLoggingVariadicFree.h" - -#define BUFFERSIZE 100 - -class AliHLTHOMERLibManager; - -/** - * @class AliHLTHOMERManager - * This Class should handle the communication - * from the HLT to aliroot. The HLT sends data via - * the HOMER interface on several TCP ports of nodes - * in the CERN GPN and DCS network. - * All this communication is hidden from the user. - * - * Right now, a xml file ( SCC1 ) is used to get the - * configuration, this will/ has to change to a proxy - * running on dedicated nodes. - * - * @ingroup alihlt_homer - */ - -class AliHLTHOMERManager : public AliHLTLogging -{ -public: - - /* - * --------------------------------------------------------------------------------- - * Constructor / Destructor - * --------------------------------------------------------------------------------- - */ - - /** default constructor */ - AliHLTHOMERManager(); - - /** destructor */ - virtual ~AliHLTHOMERManager(); - - /** Initialize - * @return 0 on success, <0 for failure - */ - Int_t Initialize(); - - /* - * --------------------------------------------------------------------------------- - * Source Handling - public - * --------------------------------------------------------------------------------- - */ - - /** Create Sources List from HOMER-Proxy - * @return 0 on success, <0 for failure, 1 for no active service - */ - virtual Int_t CreateSourcesList(); - - /** Set state of a source - * @param source Pointer to AliHLTHOMERSourceDesc object. - * @param state New (selected/not selected) state. - */ - void SetSourceState( AliHLTHOMERSourceDesc* source, Bool_t state); - - /** Get pointer to source List */ - TList* GetSourceList() { return fSourceList; } - - /* - * --------------------------------------------------------------------------------- - * Connection Handling - public - * --------------------------------------------------------------------------------- - */ - - /** Connect to HOMER sources, of a certain detector. - * which gets created when state has changed - * @param detector Detector to be connected to - * @return 0 on success, <0 for failure - */ - Int_t ConnectHOMER( TString detector="ALL" ); - - /** Disconnect from HOMER sources */ - void DisconnectHOMER(); - - /** Reconnect from HOMER sources - * @param detector Detector to be connected to - * @return 0 on success, <0 for failure - */ - Int_t ReconnectHOMER( TString detector); - - /* - * --------------------------------------------------------------------------------- - * Event Handling - public - * --------------------------------------------------------------------------------- - */ - - /** Loads the next Event, after being connected - * @return 0 on success, <0 for failure - */ - virtual Int_t NextEvent(); - - /** Loads the next Cycle, after being connected - * @return 0 on success, <0 for failure - */ - virtual Int_t NextCycle() { return NextEvent(); } - - /** Get event ID */ - ULong_t GetEventID() { return fEventID[fCurrentBufferIdx]; } - - /* --------------------------------------------------------------------------------- - * Buffer Handling - public - * --------------------------------------------------------------------------------- - */ - - /** Get pointer to last requested BlockList - * @return ptr to buffer, NULL if buffer boundary reached - */ - TList* GetBlockList() { return GetBlockListEventBuffer(fCurrentBufferIdx); } - - /** Get pointer to last asynchrounous BlockList - * @return ptr to buffer, NULL if none present - */ - TList* GetAsyncBlockList() { - cout << "Returning asyncblocklist size : " << - fAsyncBlockList->GetSize() << endl; - return fAsyncBlockList; - } - - /** Navigate backwards in event buffer - * @return index in buffer, -1 if boundary reached - */ - Int_t NavigateEventBufferBack(); - - /** Navigate forwards in event buffer - * @return index in buffer, -1 if boundary reached - */ - Int_t NavigateEventBufferFwd(); - - /* --------------------------------------------------------------------------------- - * Trigger Handling - public - * --------------------------------------------------------------------------------- - */ - - /** Set and get the string used to select triggers - * @param triggerString Trigger selection string - */ - void SetTriggerString ( TString triggerString ) { fTriggerString = triggerString; } - - /** Get TriggerString */ - TString GetTriggerString () { return fTriggerString; } - - /////////////////////////////////////////////////////////////////////////////////// - -protected: - - /** Dynamic loader manager for the HOMER library */ - AliHLTHOMERLibManager* fLibManager; //! transient - - /** Indicates, if a sources have changes, - * so that one has to reconnect. */ - Bool_t fStateHasChanged; // see above - - /////////////////////////////////////////////////////////////////////////////////// - -private: - - /** copy constructor prohibited */ - AliHLTHOMERManager(const AliHLTHOMERManager&); - - /** assignment operator prohibited */ - AliHLTHOMERManager& operator=(const AliHLTHOMERManager&); - - /* - * --------------------------------------------------------------------------------- - * Connection Handling - private - * --------------------------------------------------------------------------------- - */ - - /** Create a readout list for Hostname and ports - * @param socurceHostnames Array of selected hostnames - * @param socurcePorts Array of selected ports - * @param socurceCount Number of selected hostname:port - * @param detector detector to be selected - */ - void CreateReadoutList( const char** sourceHostnames, UShort_t* sourcePorts, - UInt_t &sourceCount, TString detector ); - - /** Checks if already connected to HOMER sources */ - Bool_t IsConnected() { return fConnected; } - - /* --------------------------------------------------------------------------------- - * Buffer Handling - private - * --------------------------------------------------------------------------------- - */ - - /** Create and add Block List to Buffer */ - void AddBlockListToBuffer(); - - /** Add bocks to asynchronous BlockList */ - void AddToAsyncBlockList(); - - /** Get pointer to block list in event buffer - * @return ptr to buffer, NULL if not present - */ - TList* GetBlockListEventBuffer( Int_t idx ); - - /* - * --------------------------------------------------------------------------------- - * Block Handling - private - * --------------------------------------------------------------------------------- - */ - - /** Get Number of blocks in current event */ - ULong_t GetNBlks() { return fNBlks; } - - // ---------------------------------------------------- - - /** Handle Blocks and fill them in event buffer or asyncronous BlockList - * @return 0 on success, <0 for failure - */ - Int_t HandleBlocks(); - - /** Check is block are from syncronous source - * @return kTRUE, if asyncronous kFALSE - */ - Bool_t IsSyncBlocks(); - - // ---------------------------------------------------- - - /** Get pointer to block ndx in current event - * @param ndx Block index - * @return returns pointer to blk, NULL if no block present - */ - void* GetBlk( Int_t ndx ); - - /** Get pointer to current block in current event */ - void* GetBlk() { return GetBlk(fCurrentBlk); } - - /** Get first block in current event */ - void* GetFirstBlk() { fCurrentBlk=0; return GetBlk(0); } - - /** Get next block in current event */ - void* GetNextBlk() { return GetBlk(++fCurrentBlk); } - - // ---------------------------------------------------- - - /** Get size of block ndx - * @param ndx Block index - * @return returns size blk, 0 otherwise - */ - ULong_t GetBlkSize( Int_t ndx ); - - /** Get size of current block */ - ULong_t GetBlkSize() { return GetBlkSize( fCurrentBlk ); } - - // ---------------------------------------------------- - - /** Get origin of block ndx - * @param ndx Block index - * @return origin of block - */ - TString GetBlkOrigin( Int_t ndx ); - - /** Get origin of current block */ - TString GetBlkOrigin(){ return GetBlkOrigin( fCurrentBlk ); } - - // ---------------------------------------------------- - - /** Get type of block ndx - * @param ndx Block index - * @return type of block - */ - TString GetBlkType( Int_t ndx ); - - /** Get type of current block */ - TString GetBlkType() { return GetBlkType( fCurrentBlk ); } - - // ---------------------------------------------------- - - /** Get specification of block ndx - * @param ndx Block index - * @return specification of block - */ - ULong_t GetBlkSpecification( Int_t ndx ); - - /** Get specification of current block */ - ULong_t GetBlkSpecification() { return GetBlkSpecification( fCurrentBlk ); } - - // ---------------------------------------------------- - - /** Checks if current Block should was requested - * @return returns kTRUE, if block should was requested - */ - Bool_t CheckIfRequested( AliHLTHOMERBlockDesc* block ); - - /* --------------------------------------------------------------------------------- - * Trigger Handling - private - * --------------------------------------------------------------------------------- - */ - - /** Loops over the data block from all the readers in the readerlist until - * a triggerdecsision has been found - * Locates the triggerdecision required by fTriggerString and checks if it triggered - * @return returns kTRUE, if event was triggered, kFALSE otherwise - */ - Bool_t CheckTriggerDecision(); - - /* - * --------------------------------------------------------------------------------- - * Members - private - * --------------------------------------------------------------------------------- - */ - - /** Proxy Handler to get the list of sources */ - AliHLTHOMERProxyHandler *fProxyHandler; //! transient - - // == connection == - - /** Pointer to current HOMER reader */ - AliHLTHOMERReader *fCurrentReader; //! transient - - /** List to pointer of HOMER readers */ - TList *fReaderList; //! transient - - // == sources == - - /** List to HOMER sources */ - TList *fSourceList; //! transient - - // == events == - - /** Number of blockes in current event */ - ULong_t fNBlks; // see above - - /** EventID of current event */ - ULong64_t fEventID[BUFFERSIZE]; // see above - - /** Current block in current event */ - ULong_t fCurrentBlk; // see above - - // == Asynchronous BlockList == - - /** List containing asychronous blocks */ - TList *fAsyncBlockList; // see above - - // == event buffer == - - /** Event Buffer */ - TClonesArray *fEventBuffer; // see above - - /** Buffer index to last received event */ - Int_t fBufferTopIdx; // see above - - /** Buffer index to last received event */ - Int_t fBufferLowIdx; // see above - - /** Buffer index to current event */ - Int_t fCurrentBufferIdx; // see above - - /** Navigate index through event buffer */ - Int_t fNavigateBufferIdx; // see above - - // == states == - - /** Shows connection status */ - Bool_t fConnected; // see above - - // == trigger selection == - - /** String indicating which trigger should be used to select events */ - TString fTriggerString; // see above - - /** Number Events not triggered, before next triggered event is found */ - Int_t fNEventsNotTriggered; // see above - - /** Retry reading next event */ - Bool_t fRetryNextEvent; // see above - - ClassDef(AliHLTHOMERManager, 1); // Manage connections to HLT data-sources. -}; - -#endif +//-*- Mode: C++ -*- + +// $Id: AliHLTHOMERManager.h $ + +#ifndef ALIHLTHOMERMANAGER_H +#define ALIHLTHOMERMANAGER_H + +/* This file is property of and copyright by the ALICE HLT Project * + * ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice + */ + +/** @file AliHLTHOMERManager.h + @author Jochen Thaeder + @date + @brief Manager for HOMER in aliroot +*/ + + +#include "TClonesArray.h" +#include "TString.h" +#include "TList.h" + +#include "AliHLTHOMERSourceDesc.h" +#include "AliHLTHOMERBlockDesc.h" +#include "AliHLTHOMERReader.h" +#include "AliHLTHOMERProxyHandler.h" + +#include "AliHLTLoggingVariadicFree.h" + +#define BUFFERSIZE 100 + +class AliHLTHOMERLibManager; + +/** + * @class AliHLTHOMERManager + * This Class should handle the communication + * from the HLT to aliroot. The HLT sends data via + * the HOMER interface on several TCP ports of nodes + * in the CERN GPN and DCS network. + * All this communication is hidden from the user. + * + * Right now, a xml file ( SCC1 ) is used to get the + * configuration, this will/ has to change to a proxy + * running on dedicated nodes. + * + * @ingroup alihlt_homer + */ + +class AliHLTHOMERManager : public AliHLTLogging +{ +public: + + /* + * --------------------------------------------------------------------------------- + * Constructor / Destructor + * --------------------------------------------------------------------------------- + */ + + /** default constructor */ + AliHLTHOMERManager(); + + /** destructor */ + virtual ~AliHLTHOMERManager(); + + /** Initialize + * @return 0 on success, <0 for failure + */ + Int_t Initialize(); + + /* + * --------------------------------------------------------------------------------- + * Source Handling - public + * --------------------------------------------------------------------------------- + */ + + /** Create Sources List from HOMER-Proxy + * @return 0 on success, <0 for failure, 1 for no active service + */ + virtual Int_t CreateSourcesList(); + + /** Set state of a source + * @param source Pointer to AliHLTHOMERSourceDesc object. + * @param state New (selected/not selected) state. + */ + void SetSourceState( AliHLTHOMERSourceDesc* source, Bool_t state); + + /** Get pointer to source List */ + TList* GetSourceList() { return fSourceList; } + + /* + * --------------------------------------------------------------------------------- + * Connection Handling - public + * --------------------------------------------------------------------------------- + */ + + /** Connect to HOMER sources, of a certain detector. + * which gets created when state has changed + * @param detector Detector to be connected to + * @return 0 on success, <0 for failure + */ + Int_t ConnectHOMER( TString detector="ALL" ); + + /** Disconnect from HOMER sources */ + void DisconnectHOMER(); + + /** Reconnect from HOMER sources + * @param detector Detector to be connected to + * @return 0 on success, <0 for failure + */ + Int_t ReconnectHOMER( TString detector); + + /* + * --------------------------------------------------------------------------------- + * Event Handling - public + * --------------------------------------------------------------------------------- + */ + + /** Loads the next Event, after being connected + * @return 0 on success, <0 for failure + */ + virtual Int_t NextEvent(); + + /** Loads the next Cycle, after being connected + * @return 0 on success, <0 for failure + */ + virtual Int_t NextCycle() { return NextEvent(); } + + /** Get event ID */ + ULong_t GetEventID() { return fEventID[fCurrentBufferIdx]; } + + /* --------------------------------------------------------------------------------- + * Buffer Handling - public + * --------------------------------------------------------------------------------- + */ + + /** Get pointer to last requested BlockList + * @return ptr to buffer, NULL if buffer boundary reached + */ + TList* GetBlockList() { return GetBlockListEventBuffer(fCurrentBufferIdx); } + + /** Get pointer to last asynchrounous BlockList + * @return ptr to buffer, NULL if none present + */ + TList* GetAsyncBlockList() { + cout << "Returning asyncblocklist size : " << + fAsyncBlockList->GetSize() << endl; + return fAsyncBlockList; + } + + /** Navigate backwards in event buffer + * @return index in buffer, -1 if boundary reached + */ + Int_t NavigateEventBufferBack(); + + /** Navigate forwards in event buffer + * @return index in buffer, -1 if boundary reached + */ + Int_t NavigateEventBufferFwd(); + + /* --------------------------------------------------------------------------------- + * Trigger Handling - public + * --------------------------------------------------------------------------------- + */ + + /** Set and get the string used to select triggers + * @param triggerString Trigger selection string + */ + void SetTriggerString ( TString triggerString ) { fTriggerString = triggerString; } + + /** Get TriggerString */ + TString GetTriggerString () { return fTriggerString; } + + /////////////////////////////////////////////////////////////////////////////////// + +protected: + + /** Dynamic loader manager for the HOMER library */ + AliHLTHOMERLibManager* fLibManager; //! transient + + /** Indicates, if a sources have changes, + * so that one has to reconnect. */ + Bool_t fStateHasChanged; // see above + + /////////////////////////////////////////////////////////////////////////////////// + +private: + + /** copy constructor prohibited */ + AliHLTHOMERManager(const AliHLTHOMERManager&); + + /** assignment operator prohibited */ + AliHLTHOMERManager& operator=(const AliHLTHOMERManager&); + + /* + * --------------------------------------------------------------------------------- + * Connection Handling - private + * --------------------------------------------------------------------------------- + */ + + /** Create a readout list for Hostname and ports + * @param socurceHostnames Array of selected hostnames + * @param socurcePorts Array of selected ports + * @param socurceCount Number of selected hostname:port + * @param detector detector to be selected + */ + void CreateReadoutList( const char** sourceHostnames, UShort_t* sourcePorts, + UInt_t &sourceCount, TString detector ); + + /** Checks if already connected to HOMER sources */ + Bool_t IsConnected() { return fConnected; } + + /* --------------------------------------------------------------------------------- + * Buffer Handling - private + * --------------------------------------------------------------------------------- + */ + + /** Create and add Block List to Buffer */ + void AddBlockListToBuffer(); + + /** Add bocks to asynchronous BlockList */ + void AddToAsyncBlockList(); + + /** Get pointer to block list in event buffer + * @return ptr to buffer, NULL if not present + */ + TList* GetBlockListEventBuffer( Int_t idx ); + + /* + * --------------------------------------------------------------------------------- + * Block Handling - private + * --------------------------------------------------------------------------------- + */ + + /** Get Number of blocks in current event */ + ULong_t GetNBlks() { return fNBlks; } + + // ---------------------------------------------------- + + /** Handle Blocks and fill them in event buffer or asyncronous BlockList + * @return 0 on success, <0 for failure + */ + Int_t HandleBlocks(); + + /** Check is block are from syncronous source + * @return kTRUE, if asyncronous kFALSE + */ + Bool_t IsSyncBlocks(); + + // ---------------------------------------------------- + + /** Get pointer to block ndx in current event + * @param ndx Block index + * @return returns pointer to blk, NULL if no block present + */ + void* GetBlk( Int_t ndx ); + + /** Get pointer to current block in current event */ + void* GetBlk() { return GetBlk(fCurrentBlk); } + + /** Get first block in current event */ + void* GetFirstBlk() { fCurrentBlk=0; return GetBlk(0); } + + /** Get next block in current event */ + void* GetNextBlk() { return GetBlk(++fCurrentBlk); } + + // ---------------------------------------------------- + + /** Get size of block ndx + * @param ndx Block index + * @return returns size blk, 0 otherwise + */ + ULong_t GetBlkSize( Int_t ndx ); + + /** Get size of current block */ + ULong_t GetBlkSize() { return GetBlkSize( fCurrentBlk ); } + + // ---------------------------------------------------- + + /** Get origin of block ndx + * @param ndx Block index + * @return origin of block + */ + TString GetBlkOrigin( Int_t ndx ); + + /** Get origin of current block */ + TString GetBlkOrigin(){ return GetBlkOrigin( fCurrentBlk ); } + + // ---------------------------------------------------- + + /** Get type of block ndx + * @param ndx Block index + * @return type of block + */ + TString GetBlkType( Int_t ndx ); + + /** Get type of current block */ + TString GetBlkType() { return GetBlkType( fCurrentBlk ); } + + // ---------------------------------------------------- + + /** Get specification of block ndx + * @param ndx Block index + * @return specification of block + */ + ULong_t GetBlkSpecification( Int_t ndx ); + + /** Get specification of current block */ + ULong_t GetBlkSpecification() { return GetBlkSpecification( fCurrentBlk ); } + + // ---------------------------------------------------- + + /** Checks if current Block should was requested + * @return returns kTRUE, if block should was requested + */ + Bool_t CheckIfRequested( AliHLTHOMERBlockDesc* block ); + + /* --------------------------------------------------------------------------------- + * Trigger Handling - private + * --------------------------------------------------------------------------------- + */ + + /** Loops over the data block from all the readers in the readerlist until + * a triggerdecsision has been found + * Locates the triggerdecision required by fTriggerString and checks if it triggered + * @return returns kTRUE, if event was triggered, kFALSE otherwise + */ + Bool_t CheckTriggerDecision(); + + /* + * --------------------------------------------------------------------------------- + * Members - private + * --------------------------------------------------------------------------------- + */ + + /** Proxy Handler to get the list of sources */ + AliHLTHOMERProxyHandler *fProxyHandler; //! transient + + // == connection == + + /** Pointer to current HOMER reader */ + AliHLTHOMERReader *fCurrentReader; //! transient + + /** List to pointer of HOMER readers */ + TList *fReaderList; //! transient + + // == sources == + + /** List to HOMER sources */ + TList *fSourceList; //! transient + + // == events == + + /** Number of blockes in current event */ + ULong_t fNBlks; // see above + + /** EventID of current event */ + ULong64_t fEventID[BUFFERSIZE]; // see above + + /** Current block in current event */ + ULong_t fCurrentBlk; // see above + + // == Asynchronous BlockList == + + /** List containing asychronous blocks */ + TList *fAsyncBlockList; // see above + + // == event buffer == + + /** Event Buffer */ + TClonesArray *fEventBuffer; // see above + + /** Buffer index to last received event */ + Int_t fBufferTopIdx; // see above + + /** Buffer index to last received event */ + Int_t fBufferLowIdx; // see above + + /** Buffer index to current event */ + Int_t fCurrentBufferIdx; // see above + + /** Navigate index through event buffer */ + Int_t fNavigateBufferIdx; // see above + + // == states == + + /** Shows connection status */ + Bool_t fConnected; // see above + + // == trigger selection == + + /** String indicating which trigger should be used to select events */ + TString fTriggerString; // see above + + /** Number Events not triggered, before next triggered event is found */ + Int_t fNEventsNotTriggered; // see above + + /** Retry reading next event */ + Bool_t fRetryNextEvent; // see above + + ClassDef(AliHLTHOMERManager, 1); // Manage connections to HLT data-sources. +}; + +#endif