Moving to standard names
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERXMLHandler.cxx
CommitLineData
7279ee15 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
51ClassImp(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//##################################################################################
75AliEveHOMERXMLHandler::~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//##################################################################################
89Int_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//##################################################################################
119Int_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//##################################################################################
174Int_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 = 0;
185 TString xmlPort = 0;
186
187 TString hostname = 0;
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 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc( hostname, port );
233
234 if ( FillSourceInformation( xmlParent, source ) ) {
235 AliError( Form("Error resolving source : %s", xmlParent.Data()) );
236 iResult = 3;
237 delete source;
238 }
239 else {
240 fSourceList->Add( source );
241#if EVE_DEBUG
242 AliInfo( Form("New Source added : %s", xmlParent.Data()) );
243#endif
244 }
245
246 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
247
248 return iResult;
249}
250
251//##################################################################################
252Int_t AliEveHOMERXMLHandler::FillSourceInformation( TString xmlParent, AliHLTHOMERSourceDesc *source ) {
253 // Resolve information of source
254 // * param xmlParent ParentString out of the XML
255 // * param source Return the filled AliHLTHOMERSourceDesc object
256 // * return 0 on sucess, 1 on errorsee header file for class documentation
257
258 Int_t iResult = 0;
259
260 if ( ! xmlParent.Contains( "_" ) ) {
261 AliError( Form("Source %s could not be resolved", xmlParent.Data() ) );
262 iResult = 1;
263
264 return iResult;
265 }
266
267 // -- Get detector / subDetector / subSubDetector
268 TObjArray * parentTokens = xmlParent.Tokenize("_");
269 Int_t nParentTokens = parentTokens->GetEntries();
270
271 TString detector = ((TObjString*) parentTokens->At(0) )->GetString();
272 TString subDetector = "";
273 TString subSubDetector = "";
274 TString name = ((TObjString*) parentTokens->At(1) )->GetString();
275
276 if ( nParentTokens == 3 )
277 subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
278 else if ( nParentTokens == 4 ) {
279 subDetector = ((TObjString*) parentTokens->At(2) )->GetString();
280 subSubDetector = ((TObjString*) parentTokens->At(3) )->GetString();
281 }
282
283 // -- Apply detector corrections
284 fSrcTranslator->ApplyDetectorCorrections( detector, subDetector );
285
286 // -- Remove Leading '0' in sub detector and subsubdetector
287 subDetector.Remove( TString::kLeading, '0' );
288 subSubDetector.Remove( TString::kLeading, '0' );
289
290 // -- Set detector / subDetector / subSubDetector
291 source->SetDetectors( detector, subDetector, subSubDetector );
292
293 // -- Fill dataType / specification / className
294 iResult = fSrcTranslator->FillSourceDesc( source, name );
295
296#if EVE_DEBUG
297 AliInfo( Form("Set Source %s , Type %s, ClassName %s .", name.Data(),
298 source->GetDataType().Data(), source->GetClassName().Data()) );
299 AliInfo( Form(" Detector %s , SubDetector : %s, SubSubDetector %s .",
300 detector.Data(), subDetector.Data(), subSubDetector.Data()) );
301#endif
302
303 return iResult;
304}
305
306//##################################################################################
307TString AliEveHOMERXMLHandler::GetNodename( TString xmlHostname ) {
308 // Get xml nodename out of xml hostname
309
310 TString nodename = 0;
311
312 TXMLNode * node = NULL;
313 TXMLNode * prevNode = fRootNode->GetChildren();
314
315 while ( node = prevNode->GetNextNode() ) {
316 prevNode = node;
317
318 // -- Find only "Node" nodes, otherwise continue
319 if ( strcmp( node->GetNodeName(), "Node" ) != 0 )
320 continue;
321
322 // -- Get Attributes of current node
323 TList *attrList = node->GetAttributes();
324 TXMLAttr *attr = 0;
325 TIter next(attrList);
326
327 TString nodeId = 0;
328
329 // Get "nodeID" and "nodeName" of this "Node" node
330 while ( ( attr = (TXMLAttr*)next() ) ) {
331 if ( strcmp( attr->GetName(), "ID" ) == 0 )
332 nodeId = attr->GetValue();
333 else if ( strcmp( attr->GetName(), "hostname" ) == 0 )
334 nodename = attr->GetValue();
335 }
336
337 // -- if this is not the correct "nodeID" continue
338 if ( nodeId != xmlHostname )
339 continue;
340
341 break;
342
343 } // while ( node = prevNode->GetNextNode() ) {
344
345 return nodename;
346}