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