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