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