]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveHOMERManager.cxx
Move contents of EVE/Alieve to EVE/EveDet as most code will remain there.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveHOMERManager.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
059c30e4 9/**************************************************************************
10 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
11 * *
12 * Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
13 * for The ALICE HLT Project. *
14 * *
15 * Permission to use, copy, modify and distribute this software and its *
16 * documentation strictly for non-commercial purposes is hereby granted *
17 * without fee, provided that the above copyright notice appears in all *
18 * copies and that both the copyright notice and this permission notice *
19 * appear in the supporting documentation. The authors make no claims *
20 * about the suitability of this software for any purpose. It is *
21 * provided "as is" without express or implied warranty. *
22 **************************************************************************/
23
d810d0de 24/** @file AliEveHOMERManager.cxx
059c30e4 25 @author Jochen Thaeder
51346b82 26 @date
059c30e4 27 @brief Manger for HOMER in offline
28*/
29
30#if __GNUC__>= 3
31 using namespace std;
32#endif
33
d810d0de 34#include "AliEveHOMERManager.h"
059c30e4 35
36#define use_aliroot
37#define use_root
38#define ROWHOUGHPARAMS
39#define use_reconstruction
40#define use_newio
41#define ROOTVERSION "unchecked"
42#define ALIROOTVERSION "unchecked"
43#define __ROOT__
44#define USE_ALILOG
45#define LINUX
46
47#include "AliHLTHOMERLibManager.h"
48
49#include "AliHLTHOMERSourceDesc.h"
50#include "AliHLTHOMERBlockDesc.h"
51
d810d0de 52#include "AliEveHOMERSource.h"
6612c5b3 53
059c30e4 54#include "AliLog.h"
55
56#include "TString.h"
57#include <TApplication.h>
58#include "Riostream.h"
59#include "TXMLAttr.h"
60#include "TCollection.h"
61#include "TList.h"
62#include "TObjString.h"
63#include "TObjArray.h"
64
6612c5b3 65// ------------
66#include "AliTPCCalibPedestal.h"
67#include "AliTPCCalibPulser.h"
68#include "AliTPCCalibCE.h"
69#include "AliTPCPreprocessorOnline.h"
70#include "AliTPCCalROC.h"
71// ------------
d810d0de 72ClassImp(AliEveHOMERManager)
059c30e4 73
74/*
75 * ---------------------------------------------------------------------------------
51346b82 76 * Constructor / Destructor
77 * ---------------------------------------------------------------------------------
059c30e4 78 */
79
80//##################################################################################
d810d0de 81AliEveHOMERManager::AliEveHOMERManager( TString xmlFile ) :
82 TEveElementList("AliEveHOMERManager"),
059c30e4 83
84 fLibManager(new AliHLTHOMERLibManager),
85 fXMLFile(xmlFile),
51346b82 86 fXMLParser(NULL),
059c30e4 87 fRootNode(NULL),
88 fSourceList(NULL),
89 fReader(NULL),
90 fBlockList(NULL),
91 fNBlks(0),
92 fEventID(0),
93 fCurrentBlk(0),
94 fConnected(kFALSE),
6612c5b3 95 fStateHasChanged(kTRUE),
96 fTPCPre(NULL) {
059c30e4 97 // see header file for class documentation
98 // or
99 // refer to README to build package
100 // or
101 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
102}
103
104//##################################################################################
d810d0de 105AliEveHOMERManager::AliEveHOMERManager( const AliEveHOMERManager& m) :
84aff7a4 106 TEveElementList(m.GetName(), m.GetTitle())
059c30e4 107{
108 // see header file for class documentation
109
110 AliError( Form( "copy constructor to be tested." ) );
111}
112
113//##################################################################################
d810d0de 114AliEveHOMERManager& AliEveHOMERManager::operator=( const AliEveHOMERManager& ) {
059c30e4 115 // see header file for class documentation
116
117 AliError( Form( "assignment constructor to be tested." ) );
118 return *this;
119}
120
121//##################################################################################
d810d0de 122AliEveHOMERManager::~AliEveHOMERManager() {
059c30e4 123 // see header file for class documentation
124
125 if ( fLibManager ) {
126 if ( fReader )
127 fLibManager->DeleteReader(fReader);
128 delete fLibManager;
129 fLibManager = NULL;
130 fReader = NULL;
131 }
132
51346b82 133 if ( fXMLParser )
059c30e4 134 delete fXMLParser;
135 fXMLParser = NULL;
136
137 if ( fSourceList != NULL )
138 delete fSourceList;
139 fSourceList = NULL;
140
141 if ( fBlockList != NULL )
142 delete fBlockList;
143 fBlockList = NULL;
6612c5b3 144
145 if ( fTPCPre != NULL )
146 delete fTPCPre;
147 fTPCPre = NULL;
059c30e4 148}
149
150/*
151 * ---------------------------------------------------------------------------------
152 * Source Handling
51346b82 153 * ---------------------------------------------------------------------------------
059c30e4 154 */
155
156//##################################################################################
d810d0de 157Int_t AliEveHOMERManager::CreateHOMERSourcesList() {
059c30e4 158 // see header file for class documentation
159
160 // -- Initialize XML parser
161 if ( fXMLParser != NULL )
162 delete fXMLParser;
163 fXMLParser = NULL;
164
165 fXMLParser = new TDOMParser();
166 fXMLParser->SetValidate( kFALSE );
51346b82 167
059c30e4 168 Int_t iResult = fXMLParser->ParseFile( fXMLFile );
169 if ( iResult < 0 ) {
170 iResult = 1;
171 AliError( Form("Parsing file with error: %s", fXMLParser->GetParseCodeMessage( fXMLParser->GetParseCode() )) );
172 return iResult;
173 }
174
175 // -- Initialize sources list
176 DestroyElements();
177 if ( fSourceList != NULL )
178 delete fSourceList;
179 fSourceList = NULL;
51346b82 180
059c30e4 181 fSourceList = new TList();
182 fSourceList->SetOwner( kTRUE );
183
184 // -- Set ROOT node
185 fRootNode = fXMLParser->GetXMLDocument()->GetRootNode();
51346b82 186
059c30e4 187 TXMLNode * node = NULL;
188 TXMLNode * prevNode = fRootNode->GetChildren();
189
190 // -- Loop over all nodes
191 while ( ( node = prevNode->GetNextNode() ) ) {
192 prevNode = node;
193
194 // -- Find only "Process" nodes, otherwise continue to next node
195 if ( strcmp( node->GetNodeName(), "Proc" ) != 0 )
196 continue;
51346b82 197
059c30e4 198 // -- Get Attributes of current node
199 TList *attrList = node->GetAttributes();
200 TXMLAttr *attr = 0;
201 TIter next(attrList);
51346b82 202
059c30e4 203 while ( ( attr = (TXMLAttr*)next() ) ) {
51346b82 204
059c30e4 205 // -- Find "ID" attribute, otherwise continue to next attribute
51346b82 206 if ( strcmp( attr->GetName(), "ID" ) != 0 )
059c30e4 207 continue;
51346b82 208
059c30e4 209 TString nodeId( attr->GetValue() );
6612c5b3 210
51346b82 211 // -- Find only TDS processes
6612c5b3 212 TObjArray * nodeIdTok = nodeId.Tokenize("_");
213
214 for ( Int_t ii=0 ; ii < nodeIdTok->GetEntries() ; ii++ ) {
215 if ( ! ( (TObjString*) nodeIdTok->At(ii) )->GetString().CompareTo("TDS") ) {
216 iResult = GetTDSAttributes( node->GetChildren() );
217 if ( iResult ) {
218 AliError( Form("Error processing TDS process : %s", nodeId.Data()) );
219 }
059c30e4 220 }
6612c5b3 221 }
059c30e4 222 } // while ( ( attr = (TXMLAttr*)next() ) ) {
223
224 } // while ( ( node = prevNode->GetNextNode() ) ) {
225
226 // -- New SourceList has been created --> All Sources are new --> State has changed
227 fStateHasChanged = kTRUE;
228
229 TIter next(fSourceList);
230 AliHLTHOMERSourceDesc* src = 0;
231 while ((src = (AliHLTHOMERSourceDesc*) next())) {
d810d0de 232 AliEveHOMERSource* re = new AliEveHOMERSource
6612c5b3 233 (src,
234 Form("%s-%s-%s %s", src->GetDetector().Data(), src->GetSubDetector().Data(),
059c30e4 235 src->GetSubSubDetector().Data(), src->GetDataType().Data()),
6612c5b3 236 "Title?\nNot.");
059c30e4 237 AddElement(re);
238 }
239
240 if ( iResult ) {
241 AliWarning( Form("There have been errors, while creating the sources list.") );
242 }
243 else {
244 AliInfo( Form("New sources list created.") );
245 }
246
247 return iResult;
248}
249
250//##################################################################################
d810d0de 251void AliEveHOMERManager::SetSourceState( AliHLTHOMERSourceDesc * source, Bool_t state ) {
059c30e4 252 // see header file for class documentation
253
254 if ( source->IsSelected() != state ) {
255 source->SetState( state );
256 fStateHasChanged = kTRUE;
257 }
258
259 return;
260}
261
262//##################################################################################
d810d0de 263Int_t AliEveHOMERManager::GetTDSAttributes( TXMLNode * xmlNode ) {
059c30e4 264 // see header file for class documentation
51346b82 265
059c30e4 266 Int_t iResult = 0;
267
268 TXMLNode * attrNode = NULL;
269 TXMLNode * prevNode = xmlNode;
270
271 TString xmlHostname = 0;
272 TString xmlPort = 0;
273
51346b82 274 TString hostname = 0;
059c30e4 275 Int_t port = 0;
276
277 // -- Get hostname and port from TDS node out of XML
278 while ( ( attrNode = prevNode->GetNextNode() ) ) {
279 prevNode = attrNode;
51346b82 280
059c30e4 281 // -- Get port out of the commandline
282 if ( strcmp( attrNode->GetNodeName(), "Cmd" ) == 0 ) {
283 TString cmd( attrNode->GetText() );
51346b82 284
059c30e4 285 TObjArray * cmdTok = cmd.Tokenize(" ");
286 xmlPort = ((TObjString*) cmdTok->At(2))->GetString();
51346b82 287 }
059c30e4 288 // -- Get hostname
51346b82 289 else if ( strcmp( attrNode->GetNodeName(), "Node" ) == 0 )
059c30e4 290 xmlHostname = attrNode->GetText();
291
292 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
51346b82 293
059c30e4 294 // -- Resolve hostname and port information
295 iResult = ResolveHostPortInformation ( xmlHostname, xmlPort, hostname, port );
296 if ( iResult == 1 ) {
297 AliError( Form("Error resolving hostname : %s", xmlHostname.Data()) );
298 return iResult;
299 }
300 else if ( iResult == 2 ) {AliInfo( Form("Connection established") );
301 AliError( Form("Error resolving port : %s", xmlPort.Data()) );
302 return iResult;
303 }
304
305 // -- Reset loop to TDS node
51346b82 306 prevNode = xmlNode;
059c30e4 307
308 // -- Get Sources out of XML, resolve sources, add to sources ListxmlHostname.Data()
309 while ( ( attrNode = prevNode->GetNextNode() ) ) {
310 prevNode = attrNode;
51346b82 311
059c30e4 312 // Find only "Parent" tags, otherwise continue to next tag
51346b82 313 if ( strcmp( attrNode->GetNodeName(), "Parent" ) != 0 )
059c30e4 314 continue;
315
316 TString xmlParent = attrNode->GetText();
51346b82 317
059c30e4 318 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc( hostname, port );
51346b82 319
059c30e4 320 if ( ResolveSourceInformation( xmlParent, source ) ) {
321 iResult = 3;
322 AliError( Form("Error resolving source : %s", xmlParent.Data()) );
51346b82 323
059c30e4 324 delete source;
325 }
326 else {
327 fSourceList->Add( source );
328 AliInfo( Form("New Source added : %s", xmlParent.Data()) );
329 }
51346b82 330
059c30e4 331 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
51346b82 332
059c30e4 333 return iResult;
334}
335
336//##################################################################################
d810d0de 337Int_t AliEveHOMERManager::ResolveHostPortInformation ( TString xmlHostname, TString xmlPort, TString &hostname, Int_t &port ) {
059c30e4 338 // see header file for class documentation
339
340 Int_t iResult = 1;
341
342 // *** Resolve hostname
343
344 TXMLNode * node = NULL;
345 TXMLNode * prevNode = fRootNode->GetChildren();
6612c5b3 346 TString nodeName = 0;
059c30e4 347 while ( ( node = prevNode->GetNextNode() ) && iResult == 1 ) {
348 prevNode = node;
51346b82 349
059c30e4 350 // -- Find only "Node" nodes, otherwise continue
351 if ( strcmp( node->GetNodeName(), "Node" ) != 0 )
352 continue;
353
354 // -- Get Attributes of current node
355 TList *attrList = node->GetAttributes();
356 TXMLAttr *attr = 0;
357 TIter next(attrList);
51346b82 358
059c30e4 359 TString nodeId = 0;
6612c5b3 360 // TString nodeName = 0;
51346b82 361
059c30e4 362 // Get "nodeID" and "nodeName" of this "Node" node
363 while ( ( attr = (TXMLAttr*)next() ) ) {
364 if ( strcmp( attr->GetName(), "ID" ) == 0 )
365 nodeId = attr->GetValue();
366 else if ( strcmp( attr->GetName(), "hostname" ) == 0 )
367 nodeName = attr->GetValue();
51346b82 368 }
059c30e4 369
370 // -- if this is not the correct nodeID continue
371 if ( nodeId != xmlHostname )
372 continue;
373
374 // -- Set hostname
6612c5b3 375
376 // TEMP FIX
377 // hostname = nodeName;
378 hostname = "alihlt-dcs0";
379
059c30e4 380 iResult = 0;
381
382 break;
383
384 } // while ( ( node = prevNode->GetNextNode() ) ) {
385
386 if ( iResult ) {
387 AliError( Form("Error resolving hostname : %s", xmlHostname.Data()) );
388 return iResult;
389 }
390
391 // *** Resolve port
392
393 if ( xmlPort.IsDigit() ) {
51346b82 394
6612c5b3 395 if ( nodeName.CompareTo("feptriggerdet") ==0 ){
396 if ( xmlPort.CompareTo("49152") == 0 ){
397 port = 58140;
398 } else if ( xmlPort.CompareTo("49153") == 0 ){
399 port = 58141;
51346b82 400 }
6612c5b3 401 } else if ( nodeName.CompareTo("fepfmdaccorde") == 0 ){
402 if ( xmlPort.CompareTo("49152") == 0 ){
403 port = 58144;
404 } else if ( xmlPort.CompareTo("49153") == 0 ){
405 port = 58145;
51346b82 406 }
6612c5b3 407 } else if ( nodeName.CompareTo("feptpcao15") == 0 ){
408 if ( xmlPort.CompareTo("49152") == 0 ){
409 port = 50340;
410 } else if ( xmlPort.CompareTo("49153") == 0 ){
411 port = 50341;
412 }
413 } else if ( nodeName.CompareTo("alihlt-dcs0") == 0 ){
414 port = xmlPort.Atoi();
415 }
059c30e4 416 }
417 else {
418 AliError ( Form("Error resolving port : %s", xmlPort.Data()) );
419 iResult = 2;
420 }
421
422 // *** Summary
423
424 if ( !iResult ) {
51346b82 425 AliInfo( Form("%s:%i resolved out of %s:%s", hostname.Data(), port, xmlHostname.Data(), xmlPort.Data()) );
059c30e4 426 }
427
428 return iResult;
429}
430
431//##################################################################################
d810d0de 432Int_t AliEveHOMERManager::ResolveSourceInformation( TString xmlParent, AliHLTHOMERSourceDesc *source ) {
059c30e4 433 // see header file for class documentation
434
435 Int_t iResult = 0;
436
437 if ( ! xmlParent.Contains( "_" ) ) {
438 AliError( Form("Source %s could not be resolved", xmlParent.Data() ) );
439 iResult = 1;
440
441 return iResult;
442 }
51346b82 443
059c30e4 444 TObjArray * parentTokens = xmlParent.Tokenize("_");
51346b82 445
059c30e4 446 Int_t nEntries = parentTokens->GetEntries();
51346b82 447
059c30e4 448 TString detector = ((TObjString*) parentTokens->At(0) )->GetString();
449 TString subDetector = "";
450 TString subSubDetector = "";
451 TString dataType = "";
452 ULong_t specification = 0;
453
454 TString name = ((TObjString*) parentTokens->At(1) )->GetString();
455 TString objName = "";
51346b82 456
457 if ( nEntries == 3 )
458 subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
059c30e4 459 else if ( nEntries == 4 ) {
51346b82 460 subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
461 subSubDetector = ((TObjString*) parentTokens->At(3) )->GetString();
059c30e4 462 }
51346b82 463
059c30e4 464 // -- Corecct TPC subdetector, because in we have somtimes "A","C"
465 if ( ! detector.CompareTo("TPC") ) {
466 if ( subDetector.BeginsWith('A') ) {
467 subDetector.Remove( TString::kLeading, 'A' );
468 }
469 else if ( subDetector.BeginsWith('C') ) {
470 subDetector.Remove( TString::kLeading, 'C' );
471 Int_t tmp = subDetector.Atoi() + 18;
472 subDetector = "";
473 subDetector += tmp;
474 }
475 }
476
477 // -- Remove Leading '0' in sub detector and subsubdetector
478 subDetector.Remove( TString::kLeading, '0' );
479 subSubDetector.Remove( TString::kLeading, '0' );
480
481 // -- Set Object Names
482
483 // **** General ****
6612c5b3 484 if ( name == "RP" || name == "FP" || name == "Relay" ) {
059c30e4 485 objName = "";
486 dataType = "DDL_RAW";
487 specification = 0;
51346b82 488 }
059c30e4 489
490 // **** TPC ****
491 else if ( detector == "TPC" ) {
51346b82 492
059c30e4 493 if ( name == "CalibPedestal" ) {
494 objName = "AliTPCCalibPedestal";
495 dataType = "HIS_CAL";
496 specification = 0;
497 }
498 else if ( name == "CalibPulser" ) {
51346b82 499 objName = "AliTPCCalibPulser";
059c30e4 500 dataType = "HIS_CAL";
501 specification = 0;
502 }
6612c5b3 503 else if ( name == "CF" || name == "RelayCF" ) {
51346b82 504 objName = "AliHLTTPCClusterDataFormat";
6612c5b3 505 dataType = "CLUSTERS";
506 specification = 0;
507 }
508 else if ( name == "ESDConv" ) {
51346b82 509 objName = "AliESDEvent";
6612c5b3 510 dataType = "ESD_TREE";
511 specification = 0;
512 }
513
059c30e4 514 } // if ( detector == "TPC" ) {
515
516 // **** TRD ****
517 else if ( detector == "TRD" ) {
518
519 if ( name == "foo" ) {
520 objName = "bar";
521 dataType = "FOO_BAR";
522 specification = 0;
523 }
524 } // else if ( detector == "TRD" ) {
525
526 // **** PHOS ****
527 else if ( detector == "PHOS" ) {
528
529 } // else if ( detector == "PHOS" ) {
530
531 // **** DIMU ****
532 else if ( detector == "MUON" ) {
533
534 } // else if ( detector == "MUON" ) {
51346b82 535
059c30e4 536 // -- Fill object
537 source->SetSourceName( name, objName );
538 source->SetSourceType( specification, dataType );
539 source->SetDetectors( detector, subDetector, subSubDetector );
540
541
542 AliInfo( Form("Set Source %s , Type %s, ClassName %s .", name.Data(), dataType.Data(), objName.Data()) );
51346b82 543 AliInfo( Form(" Detector %s , SubDetector : %s, SubSubDetector %s .",
6612c5b3 544 detector.Data(), subDetector.Data(), subSubDetector.Data()) );
059c30e4 545
546 return iResult;
547}
548
549/*
550 * ---------------------------------------------------------------------------------
551 * Connection Handling
51346b82 552 * ---------------------------------------------------------------------------------
059c30e4 553 */
554
555//##################################################################################
d810d0de 556Int_t AliEveHOMERManager::ConnectHOMER(){
059c30e4 557 // see header file for class documentation
558
51346b82 559 Int_t iResult = 0;
059c30e4 560
561 // -- Check if already connected and state has not changed
562 if ( fStateHasChanged == kFALSE && IsConnected() ) {
563 AliInfo( Form("No need for reconnection.") );
564 return iResult;
565 }
51346b82 566
059c30e4 567 // -- If already connected, disconnect before connect
51346b82 568 if ( IsConnected() )
059c30e4 569 DisconnectHOMER();
570
571 // *** Create the Readoutlist
572
573 UShort_t* sourcePorts = new UShort_t [fSourceList->GetEntries()];
574 const char ** sourceHostnames = new const char* [fSourceList->GetEntries()];
575 UInt_t sourceCount = 0;
576
577 CreateReadoutList( sourceHostnames, sourcePorts, sourceCount );
51346b82 578
059c30e4 579 if ( sourceCount == 0 ) {
580 AliError(Form("No sources selected, aborting.") );
581 return iResult;
582 }
583
584 // *** Connect to data sources
51346b82 585
059c30e4 586 if ( !fReader ) {
51346b82 587 if ( fLibManager )
059c30e4 588 fReader = fLibManager->OpenReader( sourceCount, sourceHostnames, sourcePorts );
589 }
51346b82 590
059c30e4 591 iResult = fReader->GetConnectionStatus();
51346b82 592
593 if ( iResult ) {
594 // -- Connection failed
595
059c30e4 596 UInt_t ndx = fReader->GetErrorConnectionNdx();
51346b82 597
059c30e4 598 if ( ndx < sourceCount ) {
51346b82 599 AliError( Form("Error : Error establishing connection to TCP source %s:%hu: %s (%d)",
059c30e4 600 sourceHostnames[ndx], sourcePorts[ndx], strerror(iResult), iResult) );
601 }
602 else {
603 AliError( Form("Error : Error establishing connection to unknown source with index %d: %s (%d)",
604 ndx, strerror(iResult), iResult) );
605 }
606
607 if ( fReader )
608 fLibManager->DeleteReader( fReader );
609 fReader = NULL;
610
51346b82 611 }
059c30e4 612 else {
613 // -- Connection ok - set reader
51346b82 614 fConnected = kTRUE;
615
059c30e4 616 AliInfo( Form("Connection established") );
617 }
51346b82 618
059c30e4 619 delete[] sourceHostnames;
620 delete[] sourcePorts;
51346b82 621
059c30e4 622
623 // -- Get next event
624 if ( ! iResult )
625 NextEvent();
51346b82 626
059c30e4 627 return iResult;
628}
629
630//##################################################################################
d810d0de 631void AliEveHOMERManager::DisconnectHOMER(){
059c30e4 632 // see header file for class documentation
633
634 if ( ! IsConnected() )
635 return;
636
637 if ( fReader )
638 fLibManager->DeleteReader( fReader );
639 fReader = NULL;
640
641 fStateHasChanged = kTRUE;
642 fConnected = kFALSE;
51346b82 643
059c30e4 644 AliInfo( Form("Connection closed") );
645
646 return;
647}
648
649//##################################################################################
d810d0de 650Int_t AliEveHOMERManager::ReconnectHOMER(){
059c30e4 651 // see header file for class documentation
652
653 Int_t iResult = 0;
654
655 if ( IsConnected() )
656 DisconnectHOMER();
657
658 iResult = ConnectHOMER();
659 if ( iResult ) {
660 AliError( Form("Error connecting.") );
661 }
662
663 return iResult;
664}
665
666
667//##################################################################################
d810d0de 668void AliEveHOMERManager::CreateReadoutList( const char** sourceHostnames, UShort_t *sourcePorts, UInt_t &sourceCount ){
059c30e4 669 // see header file for class documentation
670
671 AliHLTHOMERSourceDesc * source= NULL;
672
673 // -- Read all sources and check if they should be read out
674 TIter next( fSourceList );
675 while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
676
51346b82 677 if ( ! source->IsSelected() )
059c30e4 678 continue;
51346b82 679
059c30e4 680 Bool_t exists = kFALSE;
681
682 // -- Loop over existing entries and check if entry is already in readout list
683 for ( UInt_t ii = 0; ii < sourceCount; ii++ ){
684 if ( !strcmp( sourceHostnames[ii], source->GetHostname().Data() ) && sourcePorts[ii] == source->GetPort() ) {
685 exists = kTRUE;
686 break;
687 }
688 }
51346b82 689
059c30e4 690 // -- Add new entires to readout list
691 if ( ! exists ) {
692 sourcePorts[sourceCount] = source->GetPort();
693 sourceHostnames[sourceCount] = source->GetHostname().Data();
694 sourceCount++;
695 }
696
697 } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
698
699 fStateHasChanged = kFALSE;
700
701 return;
702}
703
704/*
705 * ---------------------------------------------------------------------------------
d810d0de 706 * AliEveEventManager Handling
51346b82 707 * ---------------------------------------------------------------------------------
059c30e4 708 */
709
710//##################################################################################
d810d0de 711Int_t AliEveHOMERManager::NextEvent(){
059c30e4 712 // see header file for class documentation
51346b82 713
059c30e4 714 Int_t iResult = 0;
51346b82 715
059c30e4 716 if ( !fReader || ! IsConnected() ) {
717 AliWarning( Form( "Not connected yet." ) );
718 return 1;
719 }
51346b82 720
059c30e4 721 // -- Read next event data and error handling for HOMER (error codes and empty blocks)
722 while( 1 ) {
6612c5b3 723 iResult = fReader->ReadNextEvent( 20000000 /*timeout in us*/);
51346b82 724
059c30e4 725 if ( iResult == 111 || iResult == 32 || iResult == 6 ) {
726 Int_t ndx = fReader->GetErrorConnectionNdx();
727 AliError( Form("Error, No Connection to source %d: %s (%d)", ndx, strerror(iResult), iResult) );
51346b82 728
059c30e4 729 return 2;
730 }
731 else if ( iResult == 110 ) {
732 Int_t ndx = fReader->GetErrorConnectionNdx();
733 AliError( Form("Timout occured, reading event from source %d: %s (%d)", ndx, strerror(iResult), iResult) );
51346b82 734 return 3;
059c30e4 735 }
736 else if ( iResult == 56) {
737 Int_t ndx = fReader->GetErrorConnectionNdx();
738 AliError( Form("Error reading event from source %d: %s (%d) -- IRESULTRY", ndx, strerror(iResult), iResult) );
51346b82 739 continue;
059c30e4 740 }
741 else if ( iResult ) {
742 Int_t ndx = fReader->GetErrorConnectionNdx();
743 AliError( Form("General Error reading event from source %d: %s (%d)", ndx, strerror(iResult), iResult) );
744 return 2;
745 }
746 else {
747 break;
748 }
749 } // while( 1 ) {
750
51346b82 751 if ( iResult )
059c30e4 752 return iResult;
753
754
755 // -- Get blockCnt and eventID
756 fNBlks = (ULong_t) fReader->GetBlockCnt();
757 fEventID = (ULong64_t) fReader->GetEventID();
758 fCurrentBlk = 0;
759
d810d0de 760 AliInfo( Form("AliEveEventManager 0x%016LX (%Lu) with %lu blocks", fEventID, fEventID, fNBlks) );
059c30e4 761
6612c5b3 762#if 1
763
059c30e4 764 // Loop for Debug only
765 for ( ULong_t i = 0; i < fNBlks; i++ ) {
766 Char_t tmp1[9], tmp2[5];
767 memset( tmp1, 0, 9 );
768 memset( tmp2, 0, 5 );
769 void *tmp11 = tmp1;
770 ULong64_t* tmp12 = (ULong64_t*)tmp11;
771 *tmp12 = fReader->GetBlockDataType( i );
772 void *tmp21 = tmp2;
773 ULong_t* tmp22 = (ULong_t*)tmp21;
774 *tmp22 = fReader->GetBlockDataOrigin( i );
775 AliInfo( Form("Block %lu length: %lu - type: %s - origin: %s",i, fReader->GetBlockDataLength( i ), tmp1, tmp2) );
776 } // end for ( ULong_t i = 0; i < fNBlks; i++ ) {
6612c5b3 777
059c30e4 778#endif
779
780 // -- Create BlockList
781 CreateBlockList();
782
783 return iResult;
784}
785
786//##################################################################################
d810d0de 787Int_t AliEveHOMERManager::CreateBlockList() {
059c30e4 788 // see header file for class documentation
789
790 Int_t iResult = 0;
791
792 // -- Initialize block list
793 if ( fBlockList != NULL )
794 delete fBlockList;
795 fBlockList = NULL;
796
797 fBlockList = new TList();
798 fBlockList->SetOwner( kTRUE );
799
800 void* iter = GetFirstBlk();
801
802 // -- Fill block list
803 while ( iter != NULL ){
51346b82 804
059c30e4 805 // -- Create new block
51346b82 806 AliHLTHOMERBlockDesc * block = new AliHLTHOMERBlockDesc( GetBlk(), GetBlkSize(), GetBlkOrigin(),
059c30e4 807 GetBlkType(), GetBlkSpecification() );
51346b82 808
059c30e4 809 // -- Check sources list if block is requested
810 if ( CheckIfRequested( block ) )
51346b82 811 fBlockList->Add( block );
812 else
059c30e4 813 delete block;
51346b82 814
059c30e4 815 iter = GetNextBlk();
51346b82 816
059c30e4 817 } // while ( iter != NULL ){
51346b82 818
059c30e4 819 return iResult;
820}
821
822/*
823 * ---------------------------------------------------------------------------------
824 * BlockHandling
51346b82 825 * ---------------------------------------------------------------------------------
059c30e4 826 */
827
828//##################################################################################
d810d0de 829void* AliEveHOMERManager::GetBlk( Int_t ndx ) {
059c30e4 830 // see header file for class documentation
831
832 void* data = NULL;
51346b82 833
059c30e4 834 if ( !fReader || ! IsConnected() ) {
51346b82 835 AliError( Form("Not connected yet.") );
059c30e4 836 }
837 else {
51346b82 838 if ( ( ndx ) < (Int_t) fNBlks )
059c30e4 839 data = (void*) fReader->GetBlockData( ndx );
840 }
841
842 return data;
843}
844
845//##################################################################################
d810d0de 846ULong_t AliEveHOMERManager::GetBlkSize( Int_t ndx ) {
059c30e4 847 // see header file for class documentation
848
849 ULong_t length = 0;
850
851 if ( !fReader || ! IsConnected() ) {
51346b82 852 AliError( Form("Not connected yet.") );
059c30e4 853 }
854 else {
51346b82 855 if ( ( ndx ) < (Int_t) fNBlks )
059c30e4 856 length = (ULong_t) fReader->GetBlockDataLength( ndx );
857 }
858
859 return length;
860}
861
862//##################################################################################
d810d0de 863TString AliEveHOMERManager::GetBlkOrigin( Int_t ndx ) {
059c30e4 864 // see header file for class documentation
865
866 TString origin = "";
867
868 // -- Check for Connection
869 if ( !fReader || ! IsConnected() ) {
51346b82 870 AliError( Form("Not connected yet.") );
059c30e4 871 return origin;
872 }
873
874 // -- Check block index
875 if ( ( ndx ) >= (Int_t) fNBlks ) {
51346b82 876 AliError( Form("Block index %d out of range.", ndx ) );
877 return origin;
059c30e4 878 }
879
880 // -- Get origin
881 union{
882 UInt_t data;
883 Char_t array[4];
884 } reverseOrigin;
885
886 reverseOrigin.data = (UInt_t) fReader->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 return origin;
894}
895
896//##################################################################################
d810d0de 897TString AliEveHOMERManager:: GetBlkType( Int_t ndx ) {
059c30e4 898 // see header file for class documentation
899
900 TString type = "";
901
902 // -- Check for Connection
903 if ( !fReader || ! IsConnected() ) {
51346b82 904 AliError( Form("Not connected yet.") );
059c30e4 905 return type;
906 }
907
908 // -- Check blockk index
909 if ( ( ndx ) >= (Int_t) fNBlks ) {
51346b82 910 AliError( Form("Block index %d out of range.", ndx ) );
911 return type;
059c30e4 912 }
913
914 // -- Get type
915 union{
916 ULong64_t data;
917 Char_t array[8];
918 } reverseType;
919
920 reverseType.data = (ULong64_t) fReader->GetBlockDataType( ndx );
921
922 // -- Reverse the order
923 for (Int_t ii = 7; ii >= 0; ii-- )
924 if ( reverseType.array[ii] != ' ')
925 type.Append( reverseType.array[ii] );
926
927 return type;
928}
929
930
931//##################################################################################
d810d0de 932ULong_t AliEveHOMERManager:: GetBlkSpecification( Int_t ndx ) {
059c30e4 933 // see header file for class documentation
934
935 ULong_t spec = 0;
936
937
938 // -- Check for Connection
939 if ( !fReader || ! IsConnected() ) {
51346b82 940 AliError( Form("Not connected yet.") );
059c30e4 941 return spec;
942 }
943
944 // -- Check blockk index
945 if ( ( ndx ) >= (Int_t) fNBlks ) {
51346b82 946 AliError( Form("Block index %d out of range.", ndx ) );
947 return spec;
059c30e4 948 }
51346b82 949
059c30e4 950 spec = (ULong_t) fReader->GetBlockDataSpec( ndx );
951
952 return spec;
953}
954
955//##################################################################################
d810d0de 956Bool_t AliEveHOMERManager::CheckIfRequested( AliHLTHOMERBlockDesc * block ) {
059c30e4 957 // see header file for class documentation
958
959 Bool_t requested = kFALSE;
51346b82 960
059c30e4 961 AliHLTHOMERSourceDesc * source= NULL;
51346b82 962
059c30e4 963 // -- Read all sources and check if they should be read out
964 TIter next( fSourceList );
965 while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
966
51346b82 967 if ( ! source->IsSelected() )
059c30e4 968 continue;
969
970 if ( source->GetDetector().CompareTo( block->GetDetector() ) )
971 continue;
972
973 if ( source->GetDataType().CompareTo( block->GetDataType() ) )
974 continue;
975
976 if ( ! block->HasSubDetectorRange() ) {
6612c5b3 977
978 if ( source->GetSubDetector().Atoi() != block->GetSubDetector().Atoi() )
059c30e4 979 continue;
51346b82 980
059c30e4 981 if ( ! block->HasSubSubDetectorRange() ) {
51346b82 982
6612c5b3 983 // if ( source->GetSubSubDetector().Atoi() != block->GetSubSubDetector().Atoi() )
984 // continue;
51346b82 985
059c30e4 986 } // if ( ! block->HasSubSubDetectorRange ) {
987 } // if ( ! block->HasSubDetectorRange ) {
51346b82 988
059c30e4 989 requested = kTRUE;
51346b82 990
059c30e4 991 } // while ( ( source = (AliHLTHOMERSourceDesc*)next() ) ) {
51346b82 992
059c30e4 993 if ( requested) {
51346b82 994 AliInfo( Form("Block requested : %s - %s : %s/%s -> %s ", block->GetDetector().Data(), block->GetDataType().Data(),
059c30e4 995 block->GetSubDetector().Data(), block->GetSubSubDetector().Data(), block->GetClassName().Data() ) );
996 }
6612c5b3 997 else
998 AliInfo( Form("Block NOT requested : %s - %s : %s/%s -> %s ", block->GetDetector().Data(), block->GetDataType().Data(), block->GetSubDetector().Data(), block->GetSubSubDetector().Data(), block->GetClassName().Data() ) );
059c30e4 999
1000 return requested;
1001}
1002
1003//##################################################################################
d810d0de 1004void AliEveHOMERManager::TestSelect() {
059c30e4 1005 // see header file for class documentation
1006
1007 for (Int_t ii =0; ii < fSourceList->GetEntries() ; ii++ ) {
1008 if ( (ii%2) == 0 )
1009 ((AliHLTHOMERSourceDesc*) fSourceList->At(ii))->Select();
1010 }
1011}
1012
6612c5b3 1013//##################################################################################
d810d0de 1014void AliEveHOMERManager::TestSelectClass( TString objectName ) {
6612c5b3 1015 // see header file for class documentation
1016
1017 TList* srcList = GetSourceList();
51346b82 1018
6612c5b3 1019 AliHLTHOMERSourceDesc *desc = 0;
1020
1021 TIter next(srcList);
51346b82 1022
6612c5b3 1023 while ( ( desc = (AliHLTHOMERSourceDesc*)next() ) ) {
51346b82 1024 if ( ! desc->GetClassName().CompareTo( objectName ) )
6612c5b3 1025 desc->Select();
1026 }
1027}
1028
1029//##################################################################################
d810d0de 1030void AliEveHOMERManager::SelectRawTPC() {
6612c5b3 1031 // see header file for class documentation
1032
1033 TList* srcList = GetSourceList();
51346b82 1034
6612c5b3 1035 AliHLTHOMERSourceDesc *desc = 0;
1036
1037 TIter next(srcList);
51346b82 1038
6612c5b3 1039 while ( ( desc = (AliHLTHOMERSourceDesc*)next() ) ) {
1040 if ( ! desc->GetDataType().CompareTo( "DDL_RAW" ) ) {
1041 desc->Select();
1042 }
1043 }
1044}
1045
1046//##################################################################################
d810d0de 1047void AliEveHOMERManager::SelectClusterTPC() {
6612c5b3 1048 // see header file for class documentation
1049
1050 TList* srcList = GetSourceList();
51346b82 1051
6612c5b3 1052 AliHLTHOMERSourceDesc *desc = 0;
1053
1054 TIter next(srcList);
51346b82 1055
6612c5b3 1056 while ( ( desc = (AliHLTHOMERSourceDesc*)next() ) ) {
1057 if ( ! desc->GetDataType().CompareTo( "CLUSTERS" ) ) {
1058 desc->Select();
1059 }
1060 }
1061}
1062
1063//##################################################################################
d810d0de 1064void AliEveHOMERManager::SelectESDTPC() {
6612c5b3 1065 // see header file for class documentation
1066
1067 TList* srcList = GetSourceList();
51346b82 1068
6612c5b3 1069 AliHLTHOMERSourceDesc *desc = 0;
1070
1071 TIter next(srcList);
51346b82 1072
6612c5b3 1073 while ( ( desc = (AliHLTHOMERSourceDesc*)next() ) ) {
1074 if ( ! desc->GetDataType().CompareTo( "ESD_TREE" ) ) {
1075 desc->Select();
1076 }
1077 }
1078}
1079//##################################################################################
d810d0de 1080void AliEveHOMERManager::DumpTPCCalib(TString objectName, Bool_t dumpToFile) {
6612c5b3 1081 // see header file for class documentation
1082
1083 if ( fTPCPre != NULL )
1084 delete fTPCPre;
1085
1086 fTPCPre = new AliTPCPreprocessorOnline();
1087
1088 TList* blockList = GetBlockList();
1089
1090 AliHLTHOMERBlockDesc *desc = 0;
1091
1092 TIter next(blockList);
51346b82 1093
6612c5b3 1094 while ( ( desc = (AliHLTHOMERBlockDesc*)next() ) ) {
1095 if ( ! desc->IsTObject() )
1096 continue;
51346b82 1097
6612c5b3 1098 Int_t sectorTPC = 0;
1099
1100 if ( desc->GetSubSubDetector().Atoi() <= 1 ) {
1101 sectorTPC = desc->GetSubDetector().Atoi();
1102 }
1103 else {
1104 sectorTPC = 36 + desc->GetSubDetector().Atoi();
1105 }
51346b82 1106
6612c5b3 1107 if ( ! objectName.CompareTo( desc->GetClassName() ) ){
1108
1109 //
1110 // AliTPCCalibPedestal
1111 //
1112
1113 if ( ! objectName.CompareTo( "AliTPCCalibPedestal" ) ) {
1114 AliTPCCalROC* calROC = NULL;
51346b82 1115
6612c5b3 1116 AliTPCCalibPedestal * cal = (AliTPCCalibPedestal*) desc->GetTObject();
1117 if ( cal == NULL ) {
1118 cout << "error 1" << endl;
1119 continue;
1120 }
51346b82 1121
6612c5b3 1122 cal->Analyse();
1123
1124 calROC = cal->GetCalRocRMS(sectorTPC);
1125 if ( calROC == NULL ) {
1126 cout << "error 2" << endl;
1127 continue;
1128 }
51346b82 1129
6612c5b3 1130 calROC->SetName(Form("RMS_ROC%d", sectorTPC));
1131 fTPCPre->AddComponent((TObject*) calROC );
059c30e4 1132
6612c5b3 1133 calROC = cal->GetCalRocPedestal(sectorTPC);
1134 if ( calROC == NULL ) {
1135 cout << "error 3" << endl;
1136 continue;
1137 }
51346b82 1138
6612c5b3 1139
1140 calROC->SetName(Form("Pedestal_ROC%d", sectorTPC));
1141 cout << "added" << endl;
1142 fTPCPre->AddComponent((TObject*) calROC );
1143 }
1144
1145 //
1146 // AliTPCCalibPulser
1147 //
1148 /*
1149 else if ( ! objectName.CompareTo( "AliTPCCalibPulser" ) ) {
1150 AliTPCCalROC* calROC = NULL;
1151
1152 AliTPCCalibPulser * cal = (AliTPCCalibPulser*) desc->GetTObject();
1153
1154 cal->Analyse();
51346b82 1155
6612c5b3 1156 calROC = cal->GetCalRocT0(sectorTPC);
1157 calROC->SetName(Form("T0_ROC%d", sectorTPC));
1158 fTPCPre->AddComponent((TObject*) calROC );
1159
1160 calROC = cal->GetCalRocQ(sectorTPC);
1161 calROC->SetName(Form("Q_ROC%d", sectorTPC));
1162 fTPCPre->AddComponent((TObject*) calROC );
1163
1164 calROC = cal->GetCalRocRMS(sectorTPC);
1165 calROC->SetName(Form("RMS_ROC%d", sectorTPC));
1166 fTPCPre->AddComponent((TObject*) calROC );
1167
1168 calROC = cal->GetCalRocOutliers(sectorTPC);
1169 calROC->SetName(Form("Outliers_ROC%d", sectorTPC));
1170 fTPCPre->AddComponent((TObject*) calROC );
1171 }
51346b82 1172
6612c5b3 1173*/
1174 //
1175 // AliTPCCalibCE
1176 //
1177 /*
1178 else if ( ! objectName.CompareTo( "AliTPCCalibCE" ) ) {
1179 AliTPCCalROC* calROC = NULL;
1180
1181 AliTPCCalibPulser * cal = (AliTPCCalibPulser*) desc->GetTObject();
1182
1183 cal->Analyse();
51346b82 1184
6612c5b3 1185 calROC = cal->GetCalRocT0(sectorTPC);
1186 calROC->SetName(Form("T0_ROC%d", sectorTPC));
1187 fTPCPre->AddComponent((TObject*) calROC );
1188
1189 calROC = cal->GetCalRocQ(sectorTPC);
1190 calROC->SetName(Form("Q_ROC%d", sectorTPC));
1191 fTPCPre->AddComponent((TObject*) calROC );
1192
1193 calROC = cal->GetCalRocRMS(sectorTPC);
1194 calROC->SetName(Form("RMS_ROC%d", sectorTPC));
1195 fTPCPre->AddComponent((TObject*) calROC );
1196
1197 calROC = cal->GetCalRocOutliers(sectorTPC);
1198 calROC->SetName(Form("Outliers_ROC%d", sectorTPC));
1199 fTPCPre->AddComponent((TObject*) calROC );
1200 }
1201 */
1202 } // if ( ! objectName.CompareTo( desc->GetClassName() ) ) {
51346b82 1203
6612c5b3 1204 } // while ( ( desc = (AliHLTHOMERBlockDesc*)next() ) ) {
1205
1206 if ( dumpToFile ) {
1207
1208 fTPCPre->DumpToFile("pedestals.root");
1209 cout << "DUMP" << endl;
1210 }
1211
1212
1213}