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