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