]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERManager.cxx
2b2229c797fd51f0064892a7c657f0a528c655b1
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
1 //-*- Mode: C++ -*-
2 // $Id: AliHLTHOMERManager.cxx  $
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 #if __GNUC__>= 3
32    using namespace std;
33 #endif
34
35 #define EVE_DEBUG 0
36
37 #include "AliHLTHOMERManager.h"
38 // -- -- -- -- -- -- -- 
39 #include "AliHLTHOMERLibManager.h"
40 #include "AliHLTHOMERSourceDesc.h"
41 #include "AliHLTHOMERBlockDesc.h"
42 // -- -- -- -- -- -- -- 
43 #include "AliHLTGlobalTriggerDecision.h"
44 #include "AliHLTTriggerDecision.h"
45 //---------------------------
46
47 ClassImp(AliHLTHOMERManager)
48
49 /*
50  * ---------------------------------------------------------------------------------
51  *                            Constructor / Destructor
52  * ---------------------------------------------------------------------------------
53  */
54
55 //##################################################################################
56   AliHLTHOMERManager::AliHLTHOMERManager() :
57   fLibManager(new AliHLTHOMERLibManager),
58   fStateHasChanged(kTRUE),
59   fProxyHandler(NULL),
60   fCurrentReader(NULL),
61   fReaderList(NULL),
62   fSourceList(NULL),
63   fNBlks(0),
64   fEventID(),
65   fCurrentBlk(0),
66   fAsyncBlockList(NULL),
67   fEventBuffer(NULL),
68   fBufferTopIdx(-1),
69   fBufferLowIdx(-1),
70   fCurrentBufferIdx(-1),
71   fNavigateBufferIdx(-1),
72   fConnected(kFALSE), 
73   fTriggerString("ALL"), 
74   fNEventsNotTriggered(0),
75   fRetryNextEvent(kFALSE) {
76   // see header file for class documentation
77   // or
78   // refer to README to build package
79   // or
80   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
81
82 }
83
84 //##################################################################################
85 AliHLTHOMERManager::~AliHLTHOMERManager() {
86   // see header file for class documentation
87
88   if ( fLibManager ) {
89
90     if ( fReaderList ) {
91       TIter next(fReaderList);
92       TObject * object = NULL;
93       while ( ( object = next()) )
94         fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
95       
96       fReaderList->Clear();
97       delete fReaderList;
98     }
99     fReaderList = NULL;   
100     
101     delete fLibManager;
102   } 
103   fLibManager = NULL;
104
105   if ( fProxyHandler != NULL )
106     delete fProxyHandler;
107   fProxyHandler = NULL;
108
109   if ( fSourceList != NULL )
110     delete fSourceList;
111   fSourceList = NULL;
112
113   if ( fEventBuffer ) {
114     fEventBuffer->Clear();
115     delete fEventBuffer;
116   }
117   fEventBuffer = NULL;
118
119   if ( fAsyncBlockList ) {
120     fAsyncBlockList->Clear();
121     delete fAsyncBlockList;
122   }
123   fAsyncBlockList = NULL;
124 }
125
126 //##################################################################################
127 Int_t AliHLTHOMERManager::Initialize() {
128   // see header file for class documentation
129
130   Int_t iResult = 0;
131
132   // -- Initialize ProxyHandler
133   if ( !fProxyHandler )
134     fProxyHandler = new AliHLTHOMERProxyHandler();
135   
136   if ( fProxyHandler ) {
137     iResult = fProxyHandler->Initialize();
138     if (iResult)
139       HLTError(Form("Initialize of ProxyHandler failed."));
140   }
141   else {
142     iResult = -1;
143     HLTError(Form("Creating of ProxyHandler failed."));
144   }
145  
146   // -- Initialize ReaderList
147   //    List ist not owner, as reader have to be created/deleted by the LibManager
148   if( !fReaderList )
149     fReaderList = new TList();
150   
151   // -- Initialize asynchronous BlockList
152   if( !fAsyncBlockList ) {
153     fAsyncBlockList = new TList();
154     fAsyncBlockList->SetOwner(kTRUE);
155   }
156
157   // -- Initialize Event Buffer and EventID array
158   if ( !fEventBuffer ) {
159     fEventBuffer = new TClonesArray( "TList", BUFFERSIZE );
160   }
161
162   for ( Int_t idx = 0; idx < BUFFERSIZE; ++idx ) {
163     new ((*fEventBuffer)[idx]) TList( );
164     (reinterpret_cast<TList*>((*fEventBuffer)[idx]))->SetOwner(kTRUE);
165     
166     fEventID[idx] = 0;
167   }
168
169   return iResult;
170 }
171
172 /*
173  * ---------------------------------------------------------------------------------
174  *                                 Source Handling
175  * ---------------------------------------------------------------------------------
176  */
177
178 //##################################################################################
179 Int_t AliHLTHOMERManager::CreateSourcesList() {
180   // see header file for class documentation
181
182   Int_t iResult = 0;
183   
184   if ( fSourceList != NULL )
185     delete fSourceList;
186   fSourceList = NULL;
187
188   fSourceList = new TList();
189   fSourceList->SetOwner( kTRUE );
190
191   iResult = fProxyHandler->FillSourceList( fSourceList );
192   if ( iResult < 0 ) {
193     HLTWarning(Form("There have been errors, while creating the sources list."));
194   }
195   else if ( iResult > 0 ) {
196     HLTWarning(Form("No active services found."));
197   }
198   else if ( fSourceList->IsEmpty() ) {
199     HLTWarning(Form("No active services in the list."));
200     iResult = 2;
201   }
202   else {
203      HLTInfo(Form("New sources list created."));
204
205     // -- New SourceList has been created 
206     // --> All Sources are new --> State has changed
207     fStateHasChanged = kTRUE;
208   }
209
210   return iResult;
211 }
212
213 //##################################################################################
214 void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) {
215   // see header file for class documentation
216
217   if ( source->IsSelected() != state ) {
218     source->SetState( state );
219     fStateHasChanged = kTRUE;
220   }
221
222   return;
223 }
224
225 /*
226  * ---------------------------------------------------------------------------------
227  *                         Connection Handling - public
228  * ---------------------------------------------------------------------------------
229  */
230
231 //##################################################################################
232 Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
233   // see header file for class documentation
234
235   Int_t iResult = 0;
236
237   // HAck Jochen
238   //----
239   detector="ALL";
240
241   // -- Check if LibManager is present
242   if ( ! fLibManager ) {
243     HLTError(Form("No LibManager present."));
244     return -1;
245   }
246   
247   // -- Check if already connected and state has not changed
248   if ( fStateHasChanged == kFALSE && IsConnected() ) {
249     HLTInfo(Form("No need for reconnection."));
250     return 0;
251   }
252   
253   // -- If already connected, disconnect before connect
254   //    or if ReaderList already filled
255   if ( IsConnected() || fReaderList->GetSize() != 0 )
256     DisconnectHOMER();
257   
258   // -- Create the Readoutlist
259   UShort_t* sourcePorts = new UShort_t [fSourceList->GetEntries()];
260   const Char_t ** sourceHostnames = new const Char_t* [fSourceList->GetEntries()];
261   UInt_t sourceCount = 0;
262
263   CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
264   if ( sourceCount == 0 ) {
265     HLTError(Form("No sources selected, aborting."));
266     return -2;
267   }
268
269   // ***
270   // *** Connect to data sources
271   // ***
272   
273   for (UInt_t idx = 0; idx < sourceCount; idx++) {
274     
275     HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx]));
276     
277     fReaderList->Add(dynamic_cast<TObject*>(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx])));
278     AliHLTHOMERReader *reader = static_cast<AliHLTHOMERReader*>(fReaderList->Last());
279     if ( !reader ) {
280       HLTError(Form("Adding reader failed, aborting"));
281       return -3;
282     }
283
284     if ( (iResult = reader->GetConnectionStatus()) )  {
285
286       // -- Connection to source failed
287       
288       HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
289                     sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
290
291       if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) {
292         HLTInfo("The failed connection is on localhost. is SSH tunnel up????? ");
293         HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'",
294                      sourcePorts[idx], sourcePorts[idx]));
295       }
296       
297       // -- Remove reader
298       fReaderList->RemoveLast();
299
300       if ( reader )
301         fLibManager->DeleteReader( reader );
302       reader = NULL;
303       
304       HLTInfo(Form("Removed source %d,  %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx]));
305       
306     } 
307     else {
308       // -- Connection succeded
309       fConnected = kTRUE;
310
311       HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx]));
312     }
313     
314   } // for (Int_t idx = 0; idx < sourceCount; idx++) {
315   
316   delete[] sourceHostnames;
317   delete[] sourcePorts;
318
319   return iResult;
320
321 }
322
323 //##################################################################################
324 void AliHLTHOMERManager::DisconnectHOMER(){
325   // see header file for class documentation
326
327   if ( ! IsConnected() )
328     return;
329
330   if ( fReaderList && fLibManager ) {
331     TIter next(fReaderList);
332     TObject * object = NULL;
333     while ( ( object = next()) ) 
334       fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
335       
336     fReaderList->Clear();
337     delete fReaderList;
338     fReaderList = NULL;
339   }
340   
341   fStateHasChanged = kTRUE;
342   fConnected = kFALSE;
343
344   HLTInfo(Form("Connection closed."));
345
346   return;
347 }
348
349 //##################################################################################
350 Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
351   // see header file for class documentation
352   
353   Int_t iResult = 0;
354
355   if ( IsConnected() )
356     DisconnectHOMER();
357
358   iResult = ConnectHOMER(detector);
359   if ( iResult ) {
360     HLTError(Form("Error reconnecting."));
361   }
362
363   return iResult;
364 }
365
366 /*
367  * ---------------------------------------------------------------------------------
368  *                            Event Handling - public
369  * ---------------------------------------------------------------------------------
370  */
371
372 //##################################################################################
373 Int_t AliHLTHOMERManager::NextEvent(){
374  
375   // see header file for class documentation
376   
377   Int_t iResult = 0;
378   Int_t iRetryCount = 0;
379   
380   if ( !IsConnected() || fStateHasChanged ) 
381     ConnectHOMER();
382   
383   if ( !IsConnected() ) {
384     HLTWarning(Form( "Not connected yet." ));
385     return -1;
386   }
387
388   // -- Reset asyncronous BlockList
389   fAsyncBlockList->Clear();
390
391   // ***
392   // *** Loop over all readers and get new event data
393   // ***
394   
395   TIter next(fReaderList);
396   TObject * object = NULL;
397   
398   while( (object = next()) ) {
399     
400     fCurrentReader = static_cast<AliHLTHOMERReader*>(object);
401     
402     // -- Read next event data and error handling for HOMER (error codes and empty blocks)
403     while ( 1 ) {
404       
405       iResult = fCurrentReader->ReadNextEvent( 40000000 /*timeout in us*/);
406       
407       if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
408         HLTError(Form("No connection to source %d: %s (%d)", 
409                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
410         break;
411       } 
412       else if ( iResult == 110 ) {
413         HLTError(Form("Timeout occured, reading event from source %d: %s (%d)", 
414                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
415         break;
416       } 
417       else if ( iResult == 56 ) {
418         ++iRetryCount;
419       
420         if ( iRetryCount >= 20 ) {
421           HLTError(Form("Retry Failed: Error reading event from source %d: %s (%d), returning", 
422                         fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
423           break;
424         } 
425         else {
426           HLTError(Form("Retry: Error reading event from source %d: %s (%d), making another attempt (no %d out of 20)", 
427                         fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult, iRetryCount));
428           //break;
429           continue;
430         }
431       }
432       else if ( iResult ) {
433         HLTError(Form("General Error reading event from source %d: %s (%d), giving up", 
434                       fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
435         fConnected = kFALSE;
436         break;
437       } 
438       else {
439         break;
440       }
441
442     } // while( 1 ) {
443     
444     // -- Check if event could be read
445     if ( iResult )
446       continue;
447     
448     // -- Handle Blocks from current reader
449     iResult = HandleBlocks();
450     if ( iResult ) {
451       HLTError(Form("Handling of blocks failed."));
452     }
453
454   } // while( (object = next()) ) {
455
456   // -- Check if NextEvent should be recalled, 
457   //    to catch the next event with a trigger
458   if ( fRetryNextEvent ) {
459     usleep(1000000);
460     fRetryNextEvent = kFALSE;
461     
462     HLTInfo(Form("Checked trigger of %d events, without triggering", fNEventsNotTriggered));
463     return NextEvent();
464   }
465   else
466     return 0;  
467 }
468
469 /* ---------------------------------------------------------------------------------
470  *                           Buffer Handling - public
471  * ---------------------------------------------------------------------------------
472  */
473
474 //##################################################################################
475 Int_t AliHLTHOMERManager::NavigateEventBufferBack() { 
476   // see header file for class documentation
477
478   // -- reached the end of the buffer
479   if ( fNavigateBufferIdx == fBufferLowIdx )
480     return -1;
481
482   Int_t newIdx = fNavigateBufferIdx - 1;
483   if ( newIdx == -1 )
484     newIdx = BUFFERSIZE-1;
485
486   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
487
488   return newIdx;
489 }
490
491 //##################################################################################
492 Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
493   // see header file for class documentation
494
495   // -- reached the top of the buffer
496   if ( fNavigateBufferIdx == fBufferTopIdx )
497     return -1;
498
499   Int_t newIdx = fNavigateBufferIdx + 1;
500   if ( newIdx == BUFFERSIZE )
501     newIdx = 0;
502   
503   fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
504
505   return newIdx;
506 }
507
508  ///////////////////////////////////////////////////////////////////////////////////
509
510 /*
511  * ---------------------------------------------------------------------------------
512  *                            Connection Handling - private
513  * ---------------------------------------------------------------------------------
514  */
515
516 //##################################################################################
517 void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts, 
518                                             UInt_t &sourceCount, TString detector ){
519   // see header file for class documentation
520
521   AliHLTHOMERSourceDesc * source= NULL;
522
523   // -- Read all sources and check if they should be read out
524   TIter next( fSourceList );
525   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
526
527     // -- If detector NO detector name given
528     if ( ! detector.CompareTo("ALL") ) {
529       // -- Continue if source is not selected
530       // HACK Jochen
531       //if ( ! source->IsSelected() )
532       //        continue;
533     }
534     // -- DetectorName given
535     else {
536       // -- Continue if detector name doesn't match
537       if ( detector.CompareTo(source->GetDetector()) )
538         continue;
539       else
540         source->Select();
541     }
542     
543     Bool_t exists = kFALSE;
544     
545     // -- Loop over existing entries and check if entry is already in readout list
546     for ( UInt_t ii = 0; ii < sourceCount; ii++ ){
547       if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) 
548            && sourcePorts[ii] == source->GetPort() ) {
549         exists = kTRUE;
550         break;
551       }
552     }
553
554     // -- Add new entires to readout list
555     if ( ! exists ) {
556       sourcePorts[sourceCount] = source->GetPort();
557       sourceHostnames[sourceCount] = source->GetHostname().Data();
558       sourceCount++;
559     }
560
561   } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
562
563   fStateHasChanged = kFALSE;
564
565   return;
566 }
567
568 /*
569  * ---------------------------------------------------------------------------------
570  *                          Buffer Handling - private
571  * ---------------------------------------------------------------------------------
572  */
573
574 //##################################################################################
575 void AliHLTHOMERManager::AddBlockListToBuffer() {
576   // see header file for class documentation
577
578   // -- Check if event is already in buffer
579   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
580   
581   if ( fEventID[fBufferTopIdx] == eventID ) {
582     HLTInfo(Form("Event 0x%016LX (%Lu) already in buffer.", eventID, eventID));
583     return;
584   }
585
586   // -- Check if event should be selected on basis of trigger string
587   if( fTriggerString.CompareTo("ALL") ){
588     if ( !CheckTriggerDecision() ) {
589       HLTInfo(Form("Event 0x%016LX (%Lu) is not triggered by %s.", 
590                    eventID, eventID, fTriggerString.Data()));
591       return;
592     }
593   }
594   else {
595     HLTInfo("No trigger selection.");
596   }
597
598   // -- Set Top mark 
599   ++fBufferTopIdx;
600   if ( fBufferTopIdx == BUFFERSIZE )
601     fBufferTopIdx = 0;
602
603   // -- Change the low mark if necessary
604   if ( fBufferLowIdx == -1 )
605     fBufferLowIdx = 0;
606   else if ( fBufferTopIdx == fBufferLowIdx ) {
607     ++fBufferLowIdx;
608     if ( fBufferLowIdx == BUFFERSIZE )
609       fBufferLowIdx = 0;
610   }
611
612   fNavigateBufferIdx = fCurrentBufferIdx = fBufferTopIdx;    
613
614   // -- Fill EventID
615   fEventID[fBufferTopIdx] = eventID;
616
617   // -- Clear Buffer slot
618   (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
619
620
621   GetFirstBlk();
622
623   // -- Fill block list
624   do {
625
626     // -- Create new block
627     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
628     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
629                      GetBlkType(), GetBlkSpecification() );
630     
631     // -- Check sources list if block is requested
632     if ( CheckIfRequested( block ) ) {
633       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
634     }
635     else {
636       // XXX HACK Jochen
637       (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
638       // delete block;
639       // block = NULL;
640     }
641  
642   } while( GetNextBlk() );
643
644   return;
645 }
646
647 //##################################################################################
648 void AliHLTHOMERManager::AddToAsyncBlockList() {
649   // see header file for class documentation
650
651   HLTInfo("Adding blocks to the asynchroneous block list");
652
653   GetFirstBlk();
654
655   // -- Fill block list
656   do {
657     
658     // -- Create new block
659     AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
660     block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
661                      GetBlkType(), GetBlkSpecification() );
662     
663     // -- Check sources list if block is requested
664     if ( CheckIfRequested( block ) ) 
665       fAsyncBlockList->Add( block );
666     else {
667       // XXX HACK Jochen
668       fAsyncBlockList->Add( block );
669       // delete block;
670       // block = NULL;
671     }
672  
673   } while( GetNextBlk() );
674
675   return;
676 }
677 //##################################################################################
678 TList* AliHLTHOMERManager::GetBlockListEventBuffer( Int_t idx ) {
679   // see header file for class documentation
680
681   if ( idx == -1 )
682     return NULL;
683
684   return reinterpret_cast<TList*>((*fEventBuffer)[idx]);
685
686 }
687
688 /*
689  * ---------------------------------------------------------------------------------
690  *                          Block Handling - private
691  * ---------------------------------------------------------------------------------
692  */
693
694 //##################################################################################
695 Int_t AliHLTHOMERManager::HandleBlocks() {
696   // see header file for class documentation
697   
698   Int_t iResult = 0;
699
700   // -- Get blockCnt and eventID
701   fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt());
702   ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());  
703   fCurrentBlk = 0;
704
705   // -- Check if blocks present
706   if ( fNBlks ==  0 ) {
707     HLTWarning(Form("Event 0x%016LX (%Lu) with no blocks", eventID, eventID));
708     return -1;
709   }
710
711   HLTInfo(Form("Event 0x%016LX (%Lu) with %lu blocks", eventID, eventID, fNBlks));
712
713 #if EVE_DEBUG
714   // Loop for Debug only
715   for ( ULong_t ii = 0; ii < fNBlks; ii++ ) {
716     Char_t tmp1[9], tmp2[5];
717     memset( tmp1, 0, 9 );
718     memset( tmp2, 0, 5 );
719     void *tmp11 = tmp1;
720     ULong64_t* tmp12 = static_cast<ULong64_t*>(tmp11);
721     *tmp12 = fCurrentReader->GetBlockDataType(ii);
722     void *tmp21 = tmp2;
723     ULong_t* tmp22 = static_cast<ULong_t*>(tmp21);
724     *tmp22 = fCurrentReader->GetBlockDataOrigin(ii);
725     HLTInfo(Form( "Block %lu length: %lu - type: %s - origin: %s - spec 0x%08X",
726                   ii, fCurrentReader->GetBlockDataLength(ii), tmp1, tmp2, fCurrentReader->GetBlockDataSpec(ii) ));
727   } // end for ( ULong_t ii = 0; ii < fNBlks; ii++ ) {
728 #endif
729     
730   // -- Check if blocks are from syncronous source
731
732    if ( IsSyncBlocks() )
733      AddBlockListToBuffer();
734    else
735      AddToAsyncBlockList();
736     
737   return iResult;
738 }
739
740 //##################################################################################
741 Bool_t AliHLTHOMERManager::IsSyncBlocks() {
742   // see header file for class documentation
743   
744   Bool_t bResult = kFALSE;
745
746   GetFirstBlk();
747   
748   do {          
749     
750     if ( !GetBlkType().CompareTo("ALIESDV0")) {
751       bResult = kTRUE;
752       break;
753     }
754     
755     if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
756       AliHLTHOMERBlockDesc blockDesc;
757       
758       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
759                           GetBlkType(), GetBlkSpecification() );
760       if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
761
762         bResult = kTRUE;
763         break;
764       }
765     }
766
767   } while( GetNextBlk() );
768
769
770   return bResult;
771 }
772
773 //##################################################################################
774 void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
775   // see header file for class documentation
776   // Get pointer to current block in current event
777    
778   if ( !fCurrentReader || !IsConnected() ) {
779     HLTError(Form("Not connected yet."));
780     return NULL;
781   }
782   if ( ndx < static_cast<Int_t>(fNBlks) )
783     return  const_cast<void*> (fCurrentReader->GetBlockData(ndx));
784   else
785     return NULL;
786 }
787
788 //##################################################################################
789 ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
790   // see header file for class documentation
791    
792   if ( !fCurrentReader || !IsConnected() ) {
793     HLTError(Form("Not connected yet."));
794     return 0;
795   }
796   
797   if ( ndx < static_cast<Int_t>(fNBlks) )
798     return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx));
799   else
800     return 0;
801 }
802
803 //##################################################################################
804 TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
805   // see header file for class documentation
806
807   TString origin = "";
808
809   // -- Check for Connection
810   if ( !fCurrentReader || ! IsConnected() ) {
811     HLTError(Form("Not connected yet."));
812     return origin;
813   }
814
815   // -- Check block index
816   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
817     HLTError(Form("Block index %d out of range.", ndx ));
818     return origin;
819   }
820
821   // -- Get origin
822   union{
823     UInt_t data;
824     Char_t array[4];
825   } reverseOrigin;
826
827   reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx));
828
829   // -- Reverse the order
830   for (Int_t ii = 3; ii >= 0; ii-- )
831     if ( reverseOrigin.array[ii] != ' ')
832       origin.Append( reverseOrigin.array[ii] );
833
834   origin.Remove( TString::kTrailing, ' ' );
835
836   return origin;
837 }
838
839 //##################################################################################
840 TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
841   // see header file for class documentation
842
843   TString type = "";
844
845   // -- Check for Connection
846   if ( !fCurrentReader || ! IsConnected() ) {
847     HLTError(Form("Not connected yet."));
848     return type;
849   }
850
851   // -- Check block index
852   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
853     HLTError(Form("Block index %d out of range.", ndx ));
854     return type;
855   }
856
857   // -- Get type
858   union{
859     ULong64_t data;
860     Char_t array[8];
861   } reverseType;
862
863   reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx));
864
865   // -- Reverse the order
866   for (Int_t ii = 7; ii >= 0; ii-- )
867     if ( reverseType.array[ii] != ' ')
868       type.Append( reverseType.array[ii] );
869   
870   type.Remove( TString::kTrailing, ' ' );
871
872   return type;
873 }
874
875 //##################################################################################
876 ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
877   // see header file for class documentation
878
879   // -- Check for Connection
880   if ( !fCurrentReader || ! IsConnected() ) {
881     HLTError(Form("Not connected yet."));
882     return 0;
883   }
884
885   // -- Check block index
886   if ( ndx >= static_cast<Int_t>(fNBlks) ) {
887     HLTError(Form("Block index %d out of range.", ndx ));
888     return 0;
889   }
890
891   return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx));
892 }
893
894 //##################################################################################
895 Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
896   // see header file for class documentation
897
898   Bool_t requested = kFALSE;
899
900   AliHLTHOMERSourceDesc * source= NULL;
901
902   // -- Read all sources and check if they should be read out
903   TIter next( fSourceList );
904   while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
905     
906     // -- Check if source is selected
907     if ( ! source->IsSelected() )
908       continue;
909     
910     // -- Check if detector matches
911     if ( source->GetSourceName().CompareTo( block->GetBlockName() ) )
912       continue;
913
914     requested = kTRUE;
915     break;
916
917   } // while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
918   
919 #if EVE_DEBUG
920   if ( requested ) {
921     HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); 
922   }
923   else {
924     HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data())); 
925   }
926 #endif
927
928   return requested;
929 }
930
931 /* ---------------------------------------------------------------------------------
932  *                          Trigger Handling - private
933  * ---------------------------------------------------------------------------------
934  */
935
936 //##################################################################################
937 Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
938   // see header file for class documentation
939
940   Bool_t triggered = kFALSE;
941
942   if ( !fCurrentReader || !IsConnected() ) {
943     HLTError(Form("Not connected yet."));
944     return NULL;
945   }
946
947   AliHLTHOMERBlockDesc blockDesc;
948
949   GetFirstBlk();
950   
951   // -- Fill block list
952   Bool_t foundTriggerBlock = kFALSE;
953   
954   do {
955     if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) {
956       blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
957                           GetBlkType(), GetBlkSpecification() );
958
959       if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
960
961         foundTriggerBlock = kTRUE;
962         break;
963       }
964       
965     }
966   } while( GetNextBlk() );
967   
968   if ( !foundTriggerBlock ) {
969     HLTError(Form("No trigger decision object found"));
970     return kFALSE;
971   }
972
973   // -- Get the global decision object
974   AliHLTGlobalTriggerDecision* globalDecision = 
975     static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject());
976
977   if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) {
978     triggered = globalDecision->EventTriggered();
979   } 
980   else {
981     
982     for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
983        
984       const AliHLTTriggerDecision* triggerDecision = 
985         reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx));
986     
987       if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) {
988         triggered = triggerDecision->EventTriggered();
989         break;
990       }
991     } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
992   }
993
994
995
996   if ( triggered ) {
997     fRetryNextEvent = kFALSE;
998     fNEventsNotTriggered = 0;
999   }
1000   else {
1001     fRetryNextEvent = kTRUE;
1002     ++fNEventsNotTriggered;
1003   }
1004
1005   return triggered;
1006 }