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