]>
Commit | Line | Data |
---|---|---|
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 | ||
47 | ClassImp(AliHLTHOMERManager) | |
48 | ||
49 | /* | |
50 | * --------------------------------------------------------------------------------- | |
51 | * Constructor / Destructor | |
52 | * --------------------------------------------------------------------------------- | |
53 | */ | |
54 | ||
55 | //################################################################################## | |
56 | AliHLTHOMERManager::AliHLTHOMERManager() : | |
57 | fLibManager(new AliHLTHOMERLibManager), | |
58 | fStateHasChanged(kTRUE), | |
59 | fProxyHandler(NULL), | |
60 | fCurrentReader(NULL), | |
61 | fReaderList(NULL), | |
62 | fSourceList(NULL), | |
63 | fNBlks(0), | |
64 | fEventID(), | |
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 | //################################################################################## | |
90 | AliHLTHOMERManager::~AliHLTHOMERManager() { | |
91 | // see header file for class documentation | |
92 | ||
93 | if ( fLibManager ) { | |
94 | ||
95 | if ( fReaderList ) { | |
96 | TIter next(fReaderList); | |
97 | TObject * object = NULL; | |
98 | while ( ( object = next()) ) | |
99 | fLibManager->DeleteReader(static_cast<AliHLTHOMERReader*>(object) ); | |
100 | ||
101 | fReaderList->Clear(); | |
102 | delete fReaderList; | |
103 | } | |
104 | fReaderList = NULL; | |
105 | ||
106 | delete fLibManager; | |
107 | } | |
108 | fLibManager = NULL; | |
109 | ||
110 | if ( fProxyHandler != NULL ) | |
111 | delete fProxyHandler; | |
112 | fProxyHandler = NULL; | |
113 | ||
114 | if ( fSourceList != NULL ) | |
115 | delete fSourceList; | |
116 | fSourceList = NULL; | |
117 | ||
118 | if ( fEventBuffer ) { | |
119 | fEventBuffer->Clear(); | |
120 | delete fEventBuffer; | |
121 | } | |
122 | fEventBuffer = NULL; | |
123 | ||
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 | //################################################################################## | |
138 | Int_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 | //################################################################################## | |
198 | Int_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 | //################################################################################## | |
233 | void AliHLTHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) { | |
234 | // see header file for class documentation | |
235 | ||
236 | if ( source->IsSelected() != state ) { | |
237 | source->SetState( state ); | |
238 | fStateHasChanged = kTRUE; | |
239 | } | |
240 | ||
241 | return; | |
242 | } | |
243 | ||
244 | /* | |
245 | * --------------------------------------------------------------------------------- | |
246 | * Connection Handling - public | |
247 | * --------------------------------------------------------------------------------- | |
248 | */ | |
249 | ||
250 | //################################################################################## | |
251 | Int_t AliHLTHOMERManager::ConnectHOMER( TString detector ){ | |
252 | // see header file for class documentation | |
253 | ||
254 | Int_t iResult = 0; | |
255 | ||
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 | //################################################################################## | |
347 | void 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 | //################################################################################## | |
377 | Int_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 | //################################################################################## | |
400 | Int_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 | |
3186f991 | 418 | fAsyncBlockList->Delete(); |
1ad3c9f4 | 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 | //################################################################################## | |
497 | Int_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 | //################################################################################## | |
514 | Int_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 | //################################################################################## | |
545 | void 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 | //################################################################################## | |
606 | void 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 | //################################################################################## | |
687 | void 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 ); | |
1ad3c9f4 | 702 | |
703 | } while( GetNextBlk() ); | |
704 | ||
705 | return; | |
706 | } | |
fd2adb88 | 707 | //__________________________________________________________________________________ |
708 | void AliHLTHOMERManager::AddToBlockList() { | |
709 | // see header file for class documentation | |
710 | HLTInfo("Adding blocks to the synchroneous block list"); | |
711 | ||
71453f7e | 712 | ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID()); |
fd2adb88 | 713 | |
71453f7e | 714 | if ( fEventId == eventID ) { |
715 | HLTInfo(Form("Event 0x%016lX (%lu) already in buffer.", eventID, eventID)); | |
716 | return; | |
717 | } | |
718 | ||
719 | fEventId = eventID; | |
720 | ||
fd2adb88 | 721 | GetFirstBlk(); |
722 | do { | |
723 | ||
724 | AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc(); | |
725 | block->SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(), | |
726 | GetBlkType(), GetBlkSpecification() ); | |
727 | fBlockList->Add( block ); | |
728 | ||
729 | } while( GetNextBlk() ); | |
730 | } | |
731 | ||
732 | //__________________________________________________________________________________ | |
1ad3c9f4 | 733 | TList* AliHLTHOMERManager::GetBlockListEventBuffer( Int_t idx ) { |
734 | // see header file for class documentation | |
735 | ||
fd2adb88 | 736 | if(fBlockList) |
737 | return fBlockList; | |
738 | else | |
1ad3c9f4 | 739 | return NULL; |
740 | ||
fd2adb88 | 741 | if ( idx == -1 ) |
742 | return NULL; | |
743 | ||
1ad3c9f4 | 744 | return reinterpret_cast<TList*>((*fEventBuffer)[idx]); |
745 | ||
746 | } | |
747 | ||
1ad3c9f4 | 748 | |
fd2adb88 | 749 | //__________________________________________________________________________________ |
1ad3c9f4 | 750 | Int_t AliHLTHOMERManager::HandleBlocks() { |
751 | // see header file for class documentation | |
752 | ||
753 | Int_t iResult = 0; | |
754 | ||
755 | // -- Get blockCnt and eventID | |
756 | fNBlks = static_cast<ULong_t>(fCurrentReader->GetBlockCnt()); | |
757 | ULong_t eventID = static_cast<ULong64_t>(fCurrentReader->GetEventID()); | |
758 | fCurrentBlk = 0; | |
759 | ||
760 | // -- Check if blocks present | |
761 | if ( fNBlks == 0 ) { | |
6fe8cb30 | 762 | HLTWarning(Form("Event 0x%016lX (%lu) with no blocks", eventID, eventID)); |
1ad3c9f4 | 763 | return -1; |
764 | } | |
765 | ||
6fe8cb30 | 766 | HLTInfo(Form("Event 0x%016lX (%lu) with %lu blocks", eventID, eventID, fNBlks)); |
1ad3c9f4 | 767 | |
fd2adb88 | 768 | if ( IsSyncBlocks() ) { |
769 | //AddBlockListToBuffer(); | |
c8fc4838 | 770 | fBlockList->Clear(); |
fd2adb88 | 771 | AddToBlockList(); |
772 | } else { | |
773 | AddToAsyncBlockList(); | |
774 | } | |
1ad3c9f4 | 775 | |
1ad3c9f4 | 776 | return iResult; |
777 | } | |
778 | ||
fd2adb88 | 779 | //__________________________________________________________________________________ |
1ad3c9f4 | 780 | Bool_t AliHLTHOMERManager::IsSyncBlocks() { |
781 | // see header file for class documentation | |
782 | ||
783 | Bool_t bResult = kFALSE; | |
784 | ||
785 | GetFirstBlk(); | |
786 | ||
6c1e30ef | 787 | do { |
788 | ||
789 | if ( !GetBlkType().CompareTo("ALIESDV0")) { | |
1ad3c9f4 | 790 | bResult = kTRUE; |
791 | break; | |
1ad3c9f4 | 792 | } |
c8fc4838 | 793 | |
794 | if ( !GetBlkType().CompareTo("GLOBTRIG")) { | |
795 | bResult = kTRUE; | |
796 | break; | |
797 | } | |
1ad3c9f4 | 798 | |
799 | if ( !GetBlkType().CompareTo("ROOTTOBJ") ) { | |
800 | AliHLTHOMERBlockDesc blockDesc; | |
801 | ||
802 | blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(), | |
803 | GetBlkType(), GetBlkSpecification() ); | |
804 | if ( !blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) { | |
805 | ||
806 | bResult = kTRUE; | |
807 | break; | |
808 | } | |
809 | } | |
810 | ||
811 | } while( GetNextBlk() ); | |
812 | ||
813 | ||
814 | return bResult; | |
815 | } | |
816 | ||
817 | //################################################################################## | |
818 | void* AliHLTHOMERManager::GetBlk( Int_t ndx ) { | |
819 | // see header file for class documentation | |
820 | // Get pointer to current block in current event | |
821 | ||
822 | if ( !fCurrentReader || !IsConnected() ) { | |
823 | HLTError(Form("Not connected yet.")); | |
824 | return NULL; | |
825 | } | |
826 | if ( ndx < static_cast<Int_t>(fNBlks) ) | |
827 | return const_cast<void*> (fCurrentReader->GetBlockData(ndx)); | |
828 | else | |
829 | return NULL; | |
830 | } | |
831 | ||
832 | //################################################################################## | |
833 | ULong_t AliHLTHOMERManager::GetBlkSize( Int_t ndx ) { | |
834 | // see header file for class documentation | |
835 | ||
836 | if ( !fCurrentReader || !IsConnected() ) { | |
837 | HLTError(Form("Not connected yet.")); | |
838 | return 0; | |
839 | } | |
840 | ||
841 | if ( ndx < static_cast<Int_t>(fNBlks) ) | |
842 | return static_cast<ULong_t> (fCurrentReader->GetBlockDataLength(ndx)); | |
843 | else | |
844 | return 0; | |
845 | } | |
846 | ||
847 | //################################################################################## | |
848 | TString AliHLTHOMERManager::GetBlkOrigin( Int_t ndx ) { | |
849 | // see header file for class documentation | |
850 | ||
851 | TString origin = ""; | |
852 | ||
853 | // -- Check for Connection | |
854 | if ( !fCurrentReader || ! IsConnected() ) { | |
855 | HLTError(Form("Not connected yet.")); | |
856 | return origin; | |
857 | } | |
858 | ||
859 | // -- Check block index | |
860 | if ( ndx >= static_cast<Int_t>(fNBlks) ) { | |
861 | HLTError(Form("Block index %d out of range.", ndx )); | |
862 | return origin; | |
863 | } | |
864 | ||
865 | // -- Get origin | |
866 | union{ | |
867 | UInt_t data; | |
868 | Char_t array[4]; | |
869 | } reverseOrigin; | |
870 | ||
871 | reverseOrigin.data = static_cast<UInt_t>(fCurrentReader->GetBlockDataOrigin(ndx)); | |
872 | ||
873 | // -- Reverse the order | |
874 | for (Int_t ii = 3; ii >= 0; ii-- ) | |
875 | if ( reverseOrigin.array[ii] != ' ') | |
876 | origin.Append( reverseOrigin.array[ii] ); | |
877 | ||
878 | origin.Remove( TString::kTrailing, ' ' ); | |
879 | ||
880 | return origin; | |
881 | } | |
882 | ||
883 | //################################################################################## | |
884 | TString AliHLTHOMERManager::GetBlkType( Int_t ndx ) { | |
885 | // see header file for class documentation | |
886 | ||
887 | TString type = ""; | |
888 | ||
889 | // -- Check for Connection | |
890 | if ( !fCurrentReader || ! IsConnected() ) { | |
891 | HLTError(Form("Not connected yet.")); | |
892 | return type; | |
893 | } | |
894 | ||
895 | // -- Check block index | |
896 | if ( ndx >= static_cast<Int_t>(fNBlks) ) { | |
897 | HLTError(Form("Block index %d out of range.", ndx )); | |
898 | return type; | |
899 | } | |
900 | ||
901 | // -- Get type | |
902 | union{ | |
903 | ULong64_t data; | |
904 | Char_t array[8]; | |
905 | } reverseType; | |
906 | ||
907 | reverseType.data = static_cast<ULong64_t> (fCurrentReader->GetBlockDataType(ndx)); | |
908 | ||
909 | // -- Reverse the order | |
910 | for (Int_t ii = 7; ii >= 0; ii-- ) | |
911 | if ( reverseType.array[ii] != ' ') | |
912 | type.Append( reverseType.array[ii] ); | |
913 | ||
914 | type.Remove( TString::kTrailing, ' ' ); | |
915 | ||
916 | return type; | |
917 | } | |
918 | ||
919 | //################################################################################## | |
920 | ULong_t AliHLTHOMERManager::GetBlkSpecification( Int_t ndx ) { | |
921 | // see header file for class documentation | |
922 | ||
923 | // -- Check for Connection | |
924 | if ( !fCurrentReader || ! IsConnected() ) { | |
925 | HLTError(Form("Not connected yet.")); | |
926 | return 0; | |
927 | } | |
928 | ||
929 | // -- Check block index | |
930 | if ( ndx >= static_cast<Int_t>(fNBlks) ) { | |
931 | HLTError(Form("Block index %d out of range.", ndx )); | |
932 | return 0; | |
933 | } | |
934 | ||
935 | return static_cast<ULong_t>(fCurrentReader->GetBlockDataSpec(ndx)); | |
936 | } | |
937 | ||
938 | //################################################################################## | |
939 | Bool_t AliHLTHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) { | |
940 | // see header file for class documentation | |
941 | ||
942 | Bool_t requested = kFALSE; | |
943 | ||
944 | AliHLTHOMERSourceDesc * source= NULL; | |
945 | ||
946 | // -- Read all sources and check if they should be read out | |
947 | TIter next( fSourceList ); | |
948 | while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) { | |
949 | ||
950 | // -- Check if source is selected | |
951 | if ( ! source->IsSelected() ) | |
952 | continue; | |
953 | ||
954 | // -- Check if detector matches | |
955 | if ( source->GetSourceName().CompareTo( block->GetBlockName() ) ) | |
956 | continue; | |
957 | ||
958 | requested = kTRUE; | |
959 | break; | |
960 | ||
961 | } // while ( ( source = dynamic_cast<AliHLTHOMERSourceDesc*>(next()) ) ) { | |
962 | ||
963 | #if EVE_DEBUG | |
964 | if ( requested ) { | |
965 | HLTInfo(Form("Block requested : %s", block->GetBlockName().Data())); | |
966 | } | |
967 | else { | |
968 | HLTInfo(Form("Block NOT requested : %s", block->GetBlockName().Data())); | |
969 | } | |
970 | #endif | |
971 | ||
972 | return requested; | |
973 | } | |
974 | ||
975 | /* --------------------------------------------------------------------------------- | |
976 | * Trigger Handling - private | |
977 | * --------------------------------------------------------------------------------- | |
978 | */ | |
979 | ||
980 | //################################################################################## | |
981 | Bool_t AliHLTHOMERManager::CheckTriggerDecision() { | |
982 | // see header file for class documentation | |
983 | ||
984 | Bool_t triggered = kFALSE; | |
985 | ||
986 | if ( !fCurrentReader || !IsConnected() ) { | |
987 | HLTError(Form("Not connected yet.")); | |
dc466800 | 988 | return kFALSE; |
1ad3c9f4 | 989 | } |
990 | ||
991 | AliHLTHOMERBlockDesc blockDesc; | |
992 | ||
993 | GetFirstBlk(); | |
994 | ||
995 | // -- Fill block list | |
996 | Bool_t foundTriggerBlock = kFALSE; | |
997 | ||
998 | do { | |
999 | if ( (GetBlkType().CompareTo("ROOTTOBJ") == 0) ) { | |
1000 | blockDesc.SetBlock( GetBlk(), GetBlkSize(), GetBlkOrigin(), | |
1001 | GetBlkType(), GetBlkSpecification() ); | |
1002 | ||
1003 | if ( ! blockDesc.GetClassName().CompareTo("AliHLTGlobalTriggerDecision") ) { | |
1004 | ||
1005 | foundTriggerBlock = kTRUE; | |
1006 | break; | |
1007 | } | |
1008 | ||
1009 | } | |
1010 | } while( GetNextBlk() ); | |
1011 | ||
1012 | if ( !foundTriggerBlock ) { | |
1013 | HLTError(Form("No trigger decision object found")); | |
1014 | return kFALSE; | |
1015 | } | |
1016 | ||
1017 | // -- Get the global decision object | |
1018 | AliHLTGlobalTriggerDecision* globalDecision = | |
1019 | static_cast<AliHLTGlobalTriggerDecision*>(blockDesc.GetTObject()); | |
1020 | ||
1021 | if ( fTriggerString.CompareTo("HLTGlobalTrigger") == 0 ) { | |
1022 | triggered = globalDecision->EventTriggered(); | |
1023 | } | |
1024 | else { | |
1025 | ||
1026 | for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) { | |
1027 | ||
1028 | const AliHLTTriggerDecision* triggerDecision = | |
1029 | reinterpret_cast<const AliHLTTriggerDecision*>(globalDecision->InputObject(idx)); | |
1030 | ||
1031 | if ( !(fTriggerString.CompareTo(triggerDecision->Description())) ) { | |
1032 | triggered = triggerDecision->EventTriggered(); | |
1033 | break; | |
1034 | } | |
1035 | } // for (Int_t idx = 0; idx < globalDecision->NumberOfInputObjects(); idx++) { | |
1036 | } | |
1037 | ||
1038 | ||
1039 | ||
1040 | if ( triggered ) { | |
1041 | fRetryNextEvent = kFALSE; | |
1042 | fNEventsNotTriggered = 0; | |
1043 | } | |
1044 | else { | |
1045 | fRetryNextEvent = kTRUE; | |
1046 | ++fNEventsNotTriggered; | |
1047 | } | |
1048 | ||
1049 | return triggered; | |
1050 | } |