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