]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTHOMERManager.cxx
Fixed bug retuning wrong event id
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERManager.cxx
CommitLineData
1ad3c9f4 1//-*- Mode: C++ -*-
6fe8cb30 2// $Id$
1ad3c9f4 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
47ClassImp(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(),
71453f7e 65 fEventId(-1),
1ad3c9f4 66 fCurrentBlk(0),
67 fAsyncBlockList(NULL),
fd2adb88 68 fBlockList(NULL),
69 fEventBuffer(NULL),
1ad3c9f4 70 fBufferTopIdx(-1),
71 fBufferLowIdx(-1),
72 fCurrentBufferIdx(-1),
73 fNavigateBufferIdx(-1),
fd2adb88 74 fNEventsAvailable(0),
1ad3c9f4 75 fConnected(kFALSE),
76 fTriggerString("ALL"),
77 fNEventsNotTriggered(0),
fd2adb88 78 fRetryNextEvent(kFALSE),
79 fIsBlockOwner(kTRUE)
80{
1ad3c9f4 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//##################################################################################
90AliHLTHOMERManager::~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
fd2adb88 124 if(fBlockList) {
125 fBlockList->Clear();
126 delete fBlockList;
127 }
128 fBlockList = NULL;
129
1ad3c9f4 130 if ( fAsyncBlockList ) {
131 fAsyncBlockList->Clear();
132 delete fAsyncBlockList;
133 }
134 fAsyncBlockList = NULL;
135}
136
137//##################################################################################
138Int_t AliHLTHOMERManager::Initialize() {
139 // see header file for class documentation
140
fd2adb88 141 HLTInfo("Initializing");
142
1ad3c9f4 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."));
fd2adb88 153
154 } else {
1ad3c9f4 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();
6c1e30ef 167 fAsyncBlockList->SetOwner(kTRUE);
1ad3c9f4 168 }
169
fd2adb88 170 //initialize normal block list
171 if( !fBlockList ) {
172 fBlockList = new TList();
173 fBlockList->SetOwner(kFALSE);
174 }
175
1ad3c9f4 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//##################################################################################
198Int_t AliHLTHOMERManager::CreateSourcesList() {
199 // see header file for class documentation
200
201 Int_t iResult = 0;
fd2adb88 202
1ad3c9f4 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//##################################################################################
233void 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//##################################################################################
251Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){
252 // see header file for class documentation
253
254 Int_t iResult = 0;
255
ed45b754 256 // HAck Jochen
257 //----
258 detector="ALL";
259
1ad3c9f4 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
33791895 274 if ( IsConnected() || fReaderList->GetSize() != 0 ) {
275 HLTInfo(Form("IsConnected: %d fReaderList.Size: %d", IsConnected(), fReaderList->GetSize()));
1ad3c9f4 276 DisconnectHOMER();
33791895 277 }
1ad3c9f4 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 UInt_t sourceCount = 0;
282
283 CreateReadoutList( sourceHostnames, sourcePorts, sourceCount, detector );
284 if ( sourceCount == 0 ) {
285 HLTError(Form("No sources selected, aborting."));
286 return -2;
287 }
288
289 // ***
290 // *** Connect to data sources
291 // ***
292
293 for (UInt_t idx = 0; idx < sourceCount; idx++) {
294
fd2adb88 295 if (sourcePorts[idx] > 60000)
296 continue;
297
1ad3c9f4 298 HLTInfo(Form("Adding source %d as %s : %d", idx, sourceHostnames[idx], sourcePorts[idx]));
299
300 fReaderList->Add(dynamic_cast<TObject*>(fLibManager->OpenReader(sourceHostnames[idx], sourcePorts[idx])));
301 AliHLTHOMERReader *reader = static_cast<AliHLTHOMERReader*>(fReaderList->Last());
302 if ( !reader ) {
303 HLTError(Form("Adding reader failed, aborting"));
304 return -3;
305 }
306
307 if ( (iResult = reader->GetConnectionStatus()) ) {
308
309 // -- Connection to source failed
310
311 HLTError(Form("Error establishing connection to TCP source %s:%hu: %s (%d)",
312 sourceHostnames[idx], sourcePorts[idx], strerror(iResult), iResult));
313
314 if( !(TString(sourceHostnames[idx]).CompareTo("localhost")) ) {
315 HLTInfo("The failed connection is on localhost. is SSH tunnel up????? ");
316 HLTInfo(Form("Do: 'ssh -L %d:alihlt-vobox0.cern.ch:%d cernUser@lxplus.cern.ch -fN'",
317 sourcePorts[idx], sourcePorts[idx]));
318 }
319
320 // -- Remove reader
321 fReaderList->RemoveLast();
322
323 if ( reader )
324 fLibManager->DeleteReader( reader );
325 reader = NULL;
326
327 HLTInfo(Form("Removed source %d, %s : %d from sourceList", idx, sourceHostnames[idx], sourcePorts[idx]));
328
329 }
330 else {
331 // -- Connection succeded
332 fConnected = kTRUE;
333
334 HLTInfo(Form("Connection established to source %s on port %d", sourceHostnames[idx], sourcePorts[idx]));
335 }
336
337 } // for (Int_t idx = 0; idx < sourceCount; idx++) {
338
339 delete[] sourceHostnames;
340 delete[] sourcePorts;
341
342 return iResult;
343
344}
345
346//##################################################################################
347void AliHLTHOMERManager::DisconnectHOMER(){
348 // see header file for class documentation
349
33791895 350 HLTInfo("Disconnecting");
1ad3c9f4 351
352 if ( fReaderList && fLibManager ) {
33791895 353 HLTInfo("Deleting readerlist and libmanager");
1ad3c9f4 354 TIter next(fReaderList);
355 TObject * object = NULL;
356 while ( ( object = next()) )
357 fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) );
358
33791895 359
360 HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
1ad3c9f4 361 fReaderList->Clear();
33791895 362 HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
1ad3c9f4 363 delete fReaderList;
33791895 364 fReaderList = new TList ();
365 HLTInfo(Form("fReaderList size %d", fReaderList->GetSize()));
1ad3c9f4 366 }
367
368 fStateHasChanged = kTRUE;
369 fConnected = kFALSE;
33791895 370
1ad3c9f4 371 HLTInfo(Form("Connection closed."));
372
373 return;
374}
375
376//##################################################################################
377Int_t AliHLTHOMERManager::ReconnectHOMER( TString detector="" ){
378 // see header file for class documentation
379
380 Int_t iResult = 0;
381
382 if ( IsConnected() )
383 DisconnectHOMER();
384
385 iResult = ConnectHOMER(detector);
386 if ( iResult ) {
387 HLTError(Form("Error reconnecting."));
388 }
389
390 return iResult;
391}
392
393/*
394 * ---------------------------------------------------------------------------------
395 * Event Handling - public
396 * ---------------------------------------------------------------------------------
397 */
398
399//##################################################################################
400Int_t AliHLTHOMERManager::NextEvent(){
401
402 // see header file for class documentation
403
1ad3c9f4 404 Int_t iResult = 0;
405 Int_t iRetryCount = 0;
406
33791895 407 if ( !IsConnected() || fStateHasChanged ) {
408 HLTInfo("Not connected or state has changed, returning to AliEveHOMERManager, which will deal with this situation");
409 // cout << "connectecd " << IsConnected() << "haschanged "<<fStateHasChanged << endl;
410 return 55;//ConnectHOMER();
411 }
1ad3c9f4 412 if ( !IsConnected() ) {
413 HLTWarning(Form( "Not connected yet." ));
414 return -1;
415 }
416
417 // -- Reset asyncronous BlockList
418 fAsyncBlockList->Clear();
419
420 // ***
421 // *** Loop over all readers and get new event data
422 // ***
423
424 TIter next(fReaderList);
425 TObject * object = NULL;
426
427 while( (object = next()) ) {
428
429 fCurrentReader = static_cast<AliHLTHOMERReader*>(object);
430
431 // -- Read next event data and error handling for HOMER (error codes and empty blocks)
432 while ( 1 ) {
433
434 iResult = fCurrentReader->ReadNextEvent( 40000000 /*timeout in us*/);
435
436 if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
437 HLTError(Form("No connection to source %d: %s (%d)",
438 fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
439 break;
440 }
441 else if ( iResult == 110 ) {
442 HLTError(Form("Timeout occured, reading event from source %d: %s (%d)",
443 fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
444 break;
445 }
446 else if ( iResult == 56 ) {
447 ++iRetryCount;
448
449 if ( iRetryCount >= 20 ) {
450 HLTError(Form("Retry Failed: Error reading event from source %d: %s (%d), returning",
451 fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
452 break;
453 }
454 else {
455 HLTError(Form("Retry: Error reading event from source %d: %s (%d), making another attempt (no %d out of 20)",
456 fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult, iRetryCount));
457 //break;
458 continue;
459 }
460 }
461 else if ( iResult ) {
462 HLTError(Form("General Error reading event from source %d: %s (%d), giving up",
463 fCurrentReader->GetErrorConnectionNdx(), strerror(iResult), iResult));
464 fConnected = kFALSE;
465 break;
466 }
467 else {
33791895 468 HLTDebug("Successfully read out event from source");
1ad3c9f4 469 break;
470 }
471
472 } // while( 1 ) {
473
1ad3c9f4 474 // -- Check if event could be read
33791895 475 if ( iResult ) {
476 HLTInfo("Reading event from source failed");
1ad3c9f4 477 continue;
33791895 478 }
479
1ad3c9f4 480 // -- Handle Blocks from current reader
481 iResult = HandleBlocks();
482 if ( iResult ) {
483 HLTError(Form("Handling of blocks failed."));
484 }
485
486 } // while( (object = next()) ) {
487
fd2adb88 488 return 0;
1ad3c9f4 489}
490
491/* ---------------------------------------------------------------------------------
492 * Buffer Handling - public
493 * ---------------------------------------------------------------------------------
494 */
495
496//##################################################################################
497Int_t AliHLTHOMERManager::NavigateEventBufferBack() {
498 // see header file for class documentation
499
500 // -- reached the end of the buffer
501 if ( fNavigateBufferIdx == fBufferLowIdx )
502 return -1;
503
504 Int_t newIdx = fNavigateBufferIdx - 1;
505 if ( newIdx == -1 )
506 newIdx = BUFFERSIZE-1;
507
508 fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
509
510 return newIdx;
511}
512
513//##################################################################################
514Int_t AliHLTHOMERManager::NavigateEventBufferFwd() {
515 // see header file for class documentation
516
fd2adb88 517 HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
518
1ad3c9f4 519 // -- reached the top of the buffer
520 if ( fNavigateBufferIdx == fBufferTopIdx )
521 return -1;
522
523 Int_t newIdx = fNavigateBufferIdx + 1;
524 if ( newIdx == BUFFERSIZE )
525 newIdx = 0;
526
527 fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
fd2adb88 528 fNEventsAvailable -= 1;
1ad3c9f4 529
fd2adb88 530 HLTInfo(Form("fNavigateBufferIdx: %d, fCurrentBufferIdx %d, fBufferTopIdx %d", fNavigateBufferIdx, fCurrentBufferIdx, fBufferTopIdx));
531
532
533 return 0;
1ad3c9f4 534}
535
536 ///////////////////////////////////////////////////////////////////////////////////
537
538/*
539 * ---------------------------------------------------------------------------------
540 * Connection Handling - private
541 * ---------------------------------------------------------------------------------
542 */
543
544//##################################################################################
545void AliHLTHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts,
546 UInt_t &sourceCount, TString detector ){
547 // see header file for class documentation
548
549 AliHLTHOMERSourceDesc * source= NULL;
550
551 // -- Read all sources and check if they should be read out
552 TIter next( fSourceList );
553 while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
554
fd2adb88 555 ///Don't use sources from dev cluster
556 if(source->GetPort() > 60000) continue;
557
1ad3c9f4 558 // -- If detector NO detector name given
559 if ( ! detector.CompareTo("ALL") ) {
560 // -- Continue if source is not selected
ed45b754 561 // HACK Jochen
562 //if ( ! source->IsSelected() )
563 // continue;
1ad3c9f4 564 }
565 // -- DetectorName given
566 else {
567 // -- Continue if detector name doesn't match
568 if ( detector.CompareTo(source->GetDetector()) )
569 continue;
570 else
571 source->Select();
572 }
573
574 Bool_t exists = kFALSE;
575
576 // -- Loop over existing entries and check if entry is already in readout list
577 for ( UInt_t ii = 0; ii < sourceCount; ii++ ){
578 if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() )
579 && sourcePorts[ii] == source->GetPort() ) {
580 exists = kTRUE;
581 break;
582 }
583 }
584
585 // -- Add new entires to readout list
586 if ( ! exists ) {
587 sourcePorts[sourceCount] = source->GetPort();
588 sourceHostnames[sourceCount] = source->GetHostname().Data();
589 sourceCount++;
590 }
591
592 } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
593
594 fStateHasChanged = kFALSE;
595
596 return;
597}
598
599/*
600 * ---------------------------------------------------------------------------------
601 * Buffer Handling - private
602 * ---------------------------------------------------------------------------------
603 */
604
605//##################################################################################
606void AliHLTHOMERManager::AddBlockListToBuffer() {
607 // see header file for class documentation
1ad3c9f4 608 // -- Check if event is already in buffer
609 ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());
610
611 if ( fEventID[fBufferTopIdx] == eventID ) {
6fe8cb30 612 HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
1ad3c9f4 613 return;
614 }
615
616 // -- Check if event should be selected on basis of trigger string
617 if( fTriggerString.CompareTo("ALL") ){
618 if ( !CheckTriggerDecision() ) {
a7d9e86f 619 HLTInfo("Event not triggered");
1ad3c9f4 620 return;
a7d9e86f 621 } else {
622 HLTInfo("Event triggered");
1ad3c9f4 623 }
624 }
625 else {
33791895 626 HLTDebug("No trigger selection.");
1ad3c9f4 627 }
628
629 // -- Set Top mark
630 ++fBufferTopIdx;
631 if ( fBufferTopIdx == BUFFERSIZE )
632 fBufferTopIdx = 0;
633
634 // -- Change the low mark if necessary
635 if ( fBufferLowIdx == -1 )
636 fBufferLowIdx = 0;
637 else if ( fBufferTopIdx == fBufferLowIdx ) {
638 ++fBufferLowIdx;
639 if ( fBufferLowIdx == BUFFERSIZE )
640 fBufferLowIdx = 0;
641 }
642
1ad3c9f4 643
644 // -- Fill EventID
645 fEventID[fBufferTopIdx] = eventID;
646
647 // -- Clear Buffer slot
648 (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Clear();
fd2adb88 649 if(fBlockList->IsOwner()) HLTWarning("block list is owner!!");
650 HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
651 //fBlockList->Clear();
652 fBlockList = new TList();
653 HLTInfo(Form("fBlockList size %d", fBlockList->GetSize()));
1ad3c9f4 654
655 GetFirstBlk();
656
657 // -- Fill block list
658 do {
659
660 // -- Create new block
661 AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
662 block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
663 GetBlkType(), GetBlkSpecification() );
664
665 // -- Check sources list if block is requested
666 if ( CheckIfRequested( block ) ) {
667 (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
fd2adb88 668 fBlockList->Add(block);
1ad3c9f4 669 }
670 else {
671 // XXX HACK Jochen
672 (reinterpret_cast<TList*>((*fEventBuffer)[fBufferTopIdx]))->Add( block );
fd2adb88 673 fBlockList->Add(block);
1ad3c9f4 674 // delete block;
675 // block = NULL;
676 }
677
678 } while( GetNextBlk() );
679
fd2adb88 680 //We have one more event available
681 fNEventsAvailable++;
682 HLTInfo(Form("fNEventsAvailable %d", fNEventsAvailable));
1ad3c9f4 683 return;
684}
685
686//##################################################################################
687void AliHLTHOMERManager::AddToAsyncBlockList() {
688 // see header file for class documentation
689
690 HLTInfo("Adding blocks to the asynchroneous block list");
691
1ad3c9f4 692 GetFirstBlk();
693
1ad3c9f4 694 do {
695
1ad3c9f4 696 AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc();
697 block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
698 GetBlkType(), GetBlkSpecification() );
699
fd2adb88 700
701 fAsyncBlockList->Add( block );
702
1ad3c9f4 703 // -- Check sources list if block is requested
fd2adb88 704 // if ( CheckIfRequested( block ) )
705 // fAsyncBlockList->Add( block );
706 // else {
707 // // XXX HACK Jochen
708 // }
1ad3c9f4 709
710 } while( GetNextBlk() );
711
712 return;
713}
fd2adb88 714//__________________________________________________________________________________
715void AliHLTHOMERManager::AddToBlockList() {
716 // see header file for class documentation
717 HLTInfo("Adding blocks to the synchroneous block list");
718
71453f7e 719 ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());
fd2adb88 720
71453f7e 721 if ( fEventId == eventID ) {
722 HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID));
723 return;
724 }
725
726 fEventId = eventID;
727
fd2adb88 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//__________________________________________________________________________________
1ad3c9f4 740TList* AliHLTHOMERManager::GetBlockListEventBuffer( Int_t idx ) {
741 // see header file for class documentation
742
fd2adb88 743 if(fBlockList)
744 return fBlockList;
745 else
1ad3c9f4 746 return NULL;
747
fd2adb88 748 if ( idx == -1 )
749 return NULL;
750
1ad3c9f4 751 return reinterpret_cast<TList*>((*fEventBuffer)[idx]);
752
753}
754
1ad3c9f4 755
fd2adb88 756//__________________________________________________________________________________
1ad3c9f4 757Int_t AliHLTHOMERManager::HandleBlocks() {
758 // see header file for class documentation
759
760 Int_t iResult = 0;
761
762 // -- Get blockCnt and eventID
763 fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt());
764 ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID());
765 fCurrentBlk = 0;
766
767 // -- Check if blocks present
768 if ( fNBlks == 0 ) {
6fe8cb30 769 HLTWarning(Form("Event 0x%016lX (%lu) with no blocks", eventID, eventID));
1ad3c9f4 770 return -1;
771 }
772
6fe8cb30 773 HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks));
1ad3c9f4 774
fd2adb88 775 if ( IsSyncBlocks() ) {
776 //AddBlockListToBuffer();
c8fc4838 777 fBlockList->Clear();
fd2adb88 778 AddToBlockList();
779 } else {
780 AddToAsyncBlockList();
781 }
1ad3c9f4 782
1ad3c9f4 783 return iResult;
784}
785
fd2adb88 786//__________________________________________________________________________________
1ad3c9f4 787Bool_t AliHLTHOMERManager::IsSyncBlocks() {
788 // see header file for class documentation
789
790 Bool_t bResult = kFALSE;
791
792 GetFirstBlk();
793
6c1e30ef 794 do {
795
796 if ( !GetBlkType().CompareTo("ALIESDV0")) {
1ad3c9f4 797 bResult = kTRUE;
798 break;
1ad3c9f4 799 }
c8fc4838 800
801 if ( !GetBlkType().CompareTo("GLOBTRIG")) {
802 bResult = kTRUE;
803 break;
804 }
1ad3c9f4 805
806 if ( !GetBlkType().CompareTo("ROOTTOBJ") ) {
807 AliHLTHOMERBlockDesc blockDesc;
808
809 blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
810 GetBlkType(), GetBlkSpecification() );
811 if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
812
813 bResult = kTRUE;
814 break;
815 }
816 }
817
818 } while( GetNextBlk() );
819
820
821 return bResult;
822}
823
824//##################################################################################
825void* AliHLTHOMERManager::GetBlk( Int_t ndx ) {
826 // see header file for class documentation
827 // Get pointer to current block in current event
828
829 if ( !fCurrentReader || !IsConnected() ) {
830 HLTError(Form("Not connected yet."));
831 return NULL;
832 }
833 if ( ndx < static_cast<Int_t>(fNBlks) )
834 return const_cast<void*> (fCurrentReader->GetBlockData(ndx));
835 else
836 return NULL;
837}
838
839//##################################################################################
840ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) {
841 // see header file for class documentation
842
843 if ( !fCurrentReader || !IsConnected() ) {
844 HLTError(Form("Not connected yet."));
845 return 0;
846 }
847
848 if ( ndx < static_cast<Int_t>(fNBlks) )
849 return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx));
850 else
851 return 0;
852}
853
854//##################################################################################
855TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) {
856 // see header file for class documentation
857
858 TString origin = "";
859
860 // -- Check for Connection
861 if ( !fCurrentReader || ! IsConnected() ) {
862 HLTError(Form("Not connected yet."));
863 return origin;
864 }
865
866 // -- Check block index
867 if ( ndx >= static_cast<Int_t>(fNBlks) ) {
868 HLTError(Form("Block index %d out of range.", ndx ));
869 return origin;
870 }
871
872 // -- Get origin
873 union{
874 UInt_t data;
875 Char_t array[4];
876 } reverseOrigin;
877
878 reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx));
879
880 // -- Reverse the order
881 for (Int_t ii = 3; ii >= 0; ii-- )
882 if ( reverseOrigin.array[ii] != ' ')
883 origin.Append( reverseOrigin.array[ii] );
884
885 origin.Remove( TString::kTrailing, ' ' );
886
887 return origin;
888}
889
890//##################################################################################
891TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) {
892 // see header file for class documentation
893
894 TString type = "";
895
896 // -- Check for Connection
897 if ( !fCurrentReader || ! IsConnected() ) {
898 HLTError(Form("Not connected yet."));
899 return type;
900 }
901
902 // -- Check block index
903 if ( ndx >= static_cast<Int_t>(fNBlks) ) {
904 HLTError(Form("Block index %d out of range.", ndx ));
905 return type;
906 }
907
908 // -- Get type
909 union{
910 ULong64_t data;
911 Char_t array[8];
912 } reverseType;
913
914 reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx));
915
916 // -- Reverse the order
917 for (Int_t ii = 7; ii >= 0; ii-- )
918 if ( reverseType.array[ii] != ' ')
919 type.Append( reverseType.array[ii] );
920
921 type.Remove( TString::kTrailing, ' ' );
922
923 return type;
924}
925
926//##################################################################################
927ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) {
928 // see header file for class documentation
929
930 // -- Check for Connection
931 if ( !fCurrentReader || ! IsConnected() ) {
932 HLTError(Form("Not connected yet."));
933 return 0;
934 }
935
936 // -- Check block index
937 if ( ndx >= static_cast<Int_t>(fNBlks) ) {
938 HLTError(Form("Block index %d out of range.", ndx ));
939 return 0;
940 }
941
942 return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx));
943}
944
945//##################################################################################
946Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
947 // see header file for class documentation
948
949 Bool_t requested = kFALSE;
950
951 AliHLTHOMERSourceDesc * source= NULL;
952
953 // -- Read all sources and check if they should be read out
954 TIter next( fSourceList );
955 while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
956
957 // -- Check if source is selected
958 if ( ! source->IsSelected() )
959 continue;
960
961 // -- Check if detector matches
962 if ( source->GetSourceName().CompareTo( block->GetBlockName() ) )
963 continue;
964
965 requested = kTRUE;
966 break;
967
968 } // while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) {
969
970#if EVE_DEBUG
971 if ( requested ) {
972 HLTInfo(Form("Block requested : %s", block->GetBlockName().Data()));
973 }
974 else {
975 HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data()));
976 }
977#endif
978
979 return requested;
980}
981
982/* ---------------------------------------------------------------------------------
983 * Trigger Handling - private
984 * ---------------------------------------------------------------------------------
985 */
986
987//##################################################################################
988Bool_t AliHLTHOMERManager::CheckTriggerDecision() {
989 // see header file for class documentation
990
991 Bool_t triggered = kFALSE;
992
993 if ( !fCurrentReader || !IsConnected() ) {
994 HLTError(Form("Not connected yet."));
dc466800 995 return kFALSE;
1ad3c9f4 996 }
997
998 AliHLTHOMERBlockDesc blockDesc;
999
1000 GetFirstBlk();
1001
1002 // -- Fill block list
1003 Bool_t foundTriggerBlock = kFALSE;
1004
1005 do {
1006 if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) {
1007 blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(),
1008 GetBlkType(), GetBlkSpecification() );
1009
1010 if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) {
1011
1012 foundTriggerBlock = kTRUE;
1013 break;
1014 }
1015
1016 }
1017 } while( GetNextBlk() );
1018
1019 if ( !foundTriggerBlock ) {
1020 HLTError(Form("No trigger decision object found"));
1021 return kFALSE;
1022 }
1023
1024 // -- Get the global decision object
1025 AliHLTGlobalTriggerDecision* globalDecision =
1026 static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject());
1027
1028 if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) {
1029 triggered = globalDecision->EventTriggered();
1030 }
1031 else {
1032
1033 for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
1034
1035 const AliHLTTriggerDecision* triggerDecision =
1036 reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx));
1037
1038 if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) {
1039 triggered = triggerDecision->EventTriggered();
1040 break;
1041 }
1042 } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) {
1043 }
1044
1045
1046
1047 if ( triggered ) {
1048 fRetryNextEvent = kFALSE;
1049 fNEventsNotTriggered = 0;
1050 }
1051 else {
1052 fRetryNextEvent = kTRUE;
1053 ++fNEventsNotTriggered;
1054 }
1055
1056 return triggered;
1057}