]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveHLT/AliEveHOMERXMLHandler.cxx
4a2386a989219b4935025b239b4294c15cc8f42b
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERXMLHandler.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 //-*- Mode: C++ -*-
7
8 /** @file   AliEveHOMERXMLHandler.cxx
9     @author Jochen Thaeder
10     @date
11     @brief  Src Translator of HomerManger
12 */
13
14 #if __GNUC__>= 3
15    using namespace std;
16 #endif
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 #define EVE_DEBUG 1
30 // -- -- -- -- -- -- -- 
31 #include "AliEveHOMERSource.h"
32 #include "AliEveHOMERXMLHandler.h"
33 // -- -- -- -- -- -- -- 
34 #include "TString.h"
35 #include <TApplication.h>
36 #include "Riostream.h"
37 #include "TXMLAttr.h"
38 #include "TCollection.h"
39 #include "TList.h"
40 #include "TObjString.h"
41 #include "TObjArray.h"
42 // -- -- -- -- -- -- -- 
43 #include "AliLog.h"
44
45
46
47 //______________________________________________________________________________
48 //
49 // Manage connections to HLT data-sources.
50
51 ClassImp(AliEveHOMERXMLHandler)
52
53 /*
54  * ---------------------------------------------------------------------------------
55  *                            Constructor / Destructor
56  * ---------------------------------------------------------------------------------
57  */
58
59 //##################################################################################
60   AliEveHOMERXMLHandler::AliEveHOMERXMLHandler( TString xmlFile ) :
61     fXMLFile(xmlFile),
62     fXMLParser(NULL),
63     fRootNode(NULL),
64     fSrcTranslator(NULL),
65     fSourceList(NULL)
66 {
67   // This Class should handle the HLT XML config file.
68   // host the XML parser, and do all searching in the 
69   // XML File
70   
71   Initialize();
72 }
73
74 //##################################################################################
75 AliEveHOMERXMLHandler::~AliEveHOMERXMLHandler() {
76   // The destructor
77
78   if ( fXMLParser )
79     delete fXMLParser;
80   fXMLParser = NULL;
81
82   if ( fSrcTranslator != NULL )
83     delete fSrcTranslator;
84   fSrcTranslator = NULL;
85
86 }
87
88 //##################################################################################
89 Int_t AliEveHOMERXMLHandler::Initialize() {
90   // Initialize the XML Parser, set the root node
91
92   Int_t iResult = 0 ;
93
94   // -- Initialize XML parser
95   if ( fXMLParser != NULL )
96     delete fXMLParser;
97   fXMLParser = NULL;
98
99   fXMLParser = new TDOMParser();
100   fXMLParser->SetValidate( kFALSE );
101
102   iResult = fXMLParser->ParseFile( fXMLFile );
103   if ( iResult < 0 ) {
104     iResult = 1;
105     AliError( Form("Parsing file with error: %s", fXMLParser->GetParseCodeMessage( fXMLParser->GetParseCode() )) );
106     return iResult;
107   }
108   
109   // -- Set root node
110   fRootNode = fXMLParser->GetXMLDocument()->GetRootNode();
111
112   // -- Initialize Src Translator
113   fSrcTranslator = new AliEveHOMERSrcTranslator( "GPN" );
114
115   return iResult;
116 }
117
118 //##################################################################################
119 Int_t AliEveHOMERXMLHandler::FillSourceList(TList *srcList) {
120   // Files the source list of HOMER sources
121
122   fSourceList = srcList;
123
124   Int_t iResult = 0;
125
126   TXMLNode * node = NULL;
127   TXMLNode * prevNode = fRootNode->GetChildren();
128
129   // -- Loop over all nodes
130   while ( ( node = prevNode->GetNextNode() ) ) {
131     prevNode = node;
132
133     // -- Find only "Process" nodes, otherwise continue to next node
134     if ( strcmp( node->GetNodeName(), "Proc" ) != 0 )
135       continue;
136
137     // -- Get Attributes of current node
138     TList *attrList = node->GetAttributes();
139     TXMLAttr *attr = 0;
140     TIter next(attrList);
141
142     while ( ( attr = (TXMLAttr*)next() ) ) {
143
144       // -- Find "ID" attribute, otherwise continue to next attribute
145       if ( strcmp( attr->GetName(), "ID" ) != 0 )
146         continue;
147
148       TString nodeId( attr->GetValue() );
149
150       // -- Find only TDS processes
151       TObjArray * nodeIdTok = nodeId.Tokenize("_");
152
153       for ( Int_t ii=0 ; ii < nodeIdTok->GetEntries() ; ii++ ) {
154
155         if ( ! ( (TObjString*) nodeIdTok->At(ii) )->GetString().CompareTo("TDS") ) {
156
157           iResult = AddSourceTDS( node->GetChildren() );
158           if ( iResult ) {
159             AliError( Form("Error processing TDS process : %s", nodeId.Data()) );
160           }
161
162         }
163
164       } // for ( Int_t ii=0 ; ii < nodeIdTok->GetEntries() ; ii++ ) {
165
166     } // while ( ( attr = (TXMLAttr*)next() ) ) {
167
168   } // while ( ( node = prevNode->GetNextNode() ) ) {
169   
170   return iResult;
171 }
172
173 //##################################################################################
174 Int_t AliEveHOMERXMLHandler::AddSourceTDS( TXMLNode * xmlNode ) {
175   // Get Information out of a TDS process in XML file
176   // * param xmlNode   Pointer to childs of TDS node
177   // * return          0 on sucess, > 0 on errorsee header file for class documentation
178
179   Int_t iResult = 0;
180
181   TXMLNode * attrNode = NULL;
182   TXMLNode * prevNode = xmlNode;
183
184   TString xmlHostname;
185   TString xmlPort;
186
187   TString hostname;
188   Int_t port = 0;
189
190   // -- Get hostname and port from TDS node out of XML
191   while ( ( attrNode = prevNode->GetNextNode() ) ) {
192     prevNode = attrNode;
193
194     // -- Get port out of the commandline
195     if ( strcmp( attrNode->GetNodeName(), "Cmd" ) == 0 ) {
196       TString cmd( attrNode->GetText() );
197
198       TObjArray * cmdTok = cmd.Tokenize(" ");
199       xmlPort = ((TObjString*) cmdTok->At(2))->GetString();
200     }
201     // -- Get hostname
202     else if ( strcmp( attrNode->GetNodeName(), "Node" ) == 0 )
203       xmlHostname = attrNode->GetText();
204
205   } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
206
207   TString xmlNodename = GetNodename( xmlHostname );
208
209   // -- Resolve hostname and port information --
210   iResult = fSrcTranslator->Translate( xmlNodename, xmlPort, hostname, port );
211   if ( iResult ) {
212     if ( iResult == 1 )
213       { AliError( Form("Error resolving hostname : %s", xmlHostname.Data()) ); }
214     else if ( iResult == 2 )
215       { AliError( Form("Error resolving port : %s", xmlPort.Data()) ); }
216     return iResult;
217   }
218
219   // -- Reset loop to TDS node
220   prevNode = xmlNode;
221
222   // -- Get Sources out of XML, resolve sources, add to sources List
223   while ( ( attrNode = prevNode->GetNextNode() ) ) {
224     prevNode = attrNode;
225
226     // Find only "Parent" tags, otherwise continue to next tag
227     if ( strcmp( attrNode->GetNodeName(), "Parent" ) != 0 )
228       continue;
229
230     TString xmlParent = attrNode->GetText();
231
232 #if 0
233     AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc( hostname, port );
234
235     if ( FillSourceInformation( xmlParent, source ) ) {
236       AliError( Form("Error resolving source : %s", xmlParent.Data()) );
237       iResult = 3;
238       delete source;
239     }
240     else {
241       fSourceList->Add( source );
242 #if EVE_DEBUG
243       AliInfo( Form("New Source added : %s", xmlParent.Data()) );
244 #endif
245     }
246 #endif 
247   } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
248
249   return iResult;
250 }
251
252 //##################################################################################
253 Int_t AliEveHOMERXMLHandler::FillSourceInformation( TString xmlParent, AliHLTHOMERSourceDesc *source ) {
254   // Resolve information of source
255   // * param xmlParent   ParentString out of the XML
256   // * param source      Return the filled AliHLTHOMERSourceDesc object
257   // * return            0 on sucess, 1 on errorsee header file for class documentation
258
259   Int_t iResult = 0;
260
261   if ( ! xmlParent.Contains( "_" ) ) {
262     AliError( Form("Source %s could not be resolved", xmlParent.Data() ) );
263     iResult = 1;
264
265     return iResult;
266   }
267
268   // -- Get detector / subDetector / subSubDetector
269   TObjArray * parentTokens = xmlParent.Tokenize("_");
270   Int_t nParentTokens = parentTokens->GetEntries();
271
272   TString detector = ((TObjString*) parentTokens->At(0) )->GetString();
273   TString subDetector = "";
274   TString subSubDetector = "";
275   TString name = ((TObjString*) parentTokens->At(1) )->GetString();
276   
277   if ( nParentTokens == 3 )
278     subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
279   else if ( nParentTokens == 4 ) {
280     subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
281     subSubDetector = ((TObjString*) parentTokens->At(3) )->GetString();
282   }
283
284   // -- Apply detector corrections
285   fSrcTranslator->ApplyDetectorCorrections( detector, subDetector );
286
287   // -- Remove Leading '0' in sub detector and subsubdetector
288   subDetector.Remove( TString::kLeading, '0' );
289   subSubDetector.Remove( TString::kLeading, '0' );
290   
291   // -- Set detector / subDetector / subSubDetector
292   //  source->SetDetectors( detector, subDetector, subSubDetector );  
293
294   // -- Fill dataType / specification / className
295   iResult = fSrcTranslator->FillSourceDesc( source, name );
296
297 #if 0
298   AliInfo( Form("Set Source %s , Type %s, ClassName %s .", name.Data(), 
299                 source->GetDataType().Data(), source->GetClassName().Data()) );
300   AliInfo( Form("    Detector %s , SubDetector : %s, SubSubDetector %s .",
301                 detector.Data(), subDetector.Data(), subSubDetector.Data()) );
302 #endif
303
304   return iResult;
305 }
306
307 //##################################################################################
308 TString AliEveHOMERXMLHandler::GetNodename( TString xmlHostname ) {
309   // Get xml nodename out of xml hostname
310
311   TString nodename;
312
313   TXMLNode * node = NULL;
314   TXMLNode * prevNode = fRootNode->GetChildren();
315
316   while ((node = prevNode->GetNextNode()) != 0)
317   {
318     prevNode = node;
319
320     // -- Find only "Node" nodes, otherwise continue
321     if ( strcmp( node->GetNodeName(), "Node" ) != 0 )
322       continue;
323
324     // -- Get Attributes of current node
325     TList *attrList = node->GetAttributes();
326     TXMLAttr *attr = 0;
327     TIter next(attrList);
328
329     TString nodeId;
330
331     // Get "nodeID" and "nodeName" of this "Node" node
332     while ( ( attr = (TXMLAttr*)next() ) ) {
333       if ( strcmp( attr->GetName(), "ID" ) == 0 )
334         nodeId = attr->GetValue();
335       else if ( strcmp( attr->GetName(), "hostname" ) == 0 )
336         nodename = attr->GetValue();
337     }
338
339     // -- if this is not the correct "nodeID" continue
340     if ( nodeId != xmlHostname )
341       continue;
342
343     break;
344
345   } // while ( node = prevNode->GetNextNode() ) {
346
347   return nodename;
348 }