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. *
8 /** @file AliEveHOMERXMLHandler.cxx
11 @brief Src Translator of HomerManger
20 #define ROWHOUGHPARAMS
21 #define use_reconstruction
23 #define ROOTVERSION "unchecked"
24 #define ALIROOTVERSION "unchecked"
30 // -- -- -- -- -- -- --
31 #include "AliEveHOMERSource.h"
32 #include "AliEveHOMERXMLHandler.h"
33 // -- -- -- -- -- -- --
35 #include <TApplication.h>
36 #include "Riostream.h"
38 #include "TCollection.h"
40 #include "TObjString.h"
41 #include "TObjArray.h"
42 // -- -- -- -- -- -- --
47 //______________________________________________________________________________
49 // Manage connections to HLT data-sources.
51 ClassImp(AliEveHOMERXMLHandler)
54 * ---------------------------------------------------------------------------------
55 * Constructor / Destructor
56 * ---------------------------------------------------------------------------------
59 //##################################################################################
60 AliEveHOMERXMLHandler::AliEveHOMERXMLHandler( TString xmlFile ) :
67 // This Class should handle the HLT XML config file.
68 // host the XML parser, and do all searching in the
74 //##################################################################################
75 AliEveHOMERXMLHandler::~AliEveHOMERXMLHandler() {
82 if ( fSrcTranslator != NULL )
83 delete fSrcTranslator;
84 fSrcTranslator = NULL;
88 //##################################################################################
89 Int_t AliEveHOMERXMLHandler::Initialize() {
90 // Initialize the XML Parser, set the root node
94 // -- Initialize XML parser
95 if ( fXMLParser != NULL )
99 fXMLParser = new TDOMParser();
100 fXMLParser->SetValidate( kFALSE );
102 iResult = fXMLParser->ParseFile( fXMLFile );
105 AliError( Form("Parsing file with error: %s", fXMLParser->GetParseCodeMessage( fXMLParser->GetParseCode() )) );
110 fRootNode = fXMLParser->GetXMLDocument()->GetRootNode();
112 // -- Initialize Src Translator
113 fSrcTranslator = new AliEveHOMERSrcTranslator( "GPN" );
118 //##################################################################################
119 Int_t AliEveHOMERXMLHandler::FillSourceList(TList *srcList) {
120 // Files the source list of HOMER sources
122 fSourceList = srcList;
126 TXMLNode * node = NULL;
127 TXMLNode * prevNode = fRootNode->GetChildren();
129 // -- Loop over all nodes
130 while ( ( node = prevNode->GetNextNode() ) ) {
133 // -- Find only "Process" nodes, otherwise continue to next node
134 if ( strcmp( node->GetNodeName(), "Proc" ) != 0 )
137 // -- Get Attributes of current node
138 TList *attrList = node->GetAttributes();
140 TIter next(attrList);
142 while ( ( attr = (TXMLAttr*)next() ) ) {
144 // -- Find "ID" attribute, otherwise continue to next attribute
145 if ( strcmp( attr->GetName(), "ID" ) != 0 )
148 TString nodeId( attr->GetValue() );
150 // -- Find only TDS processes
151 TObjArray * nodeIdTok = nodeId.Tokenize("_");
153 for ( Int_t ii=0 ; ii < nodeIdTok->GetEntries() ; ii++ ) {
155 if ( ! ( (TObjString*) nodeIdTok->At(ii) )->GetString().CompareTo("TDS") ) {
157 iResult = AddSourceTDS( node->GetChildren() );
159 AliError( Form("Error processing TDS process : %s", nodeId.Data()) );
164 } // for ( Int_t ii=0 ; ii < nodeIdTok->GetEntries() ; ii++ ) {
166 } // while ( ( attr = (TXMLAttr*)next() ) ) {
168 } // while ( ( node = prevNode->GetNextNode() ) ) {
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
181 TXMLNode * attrNode = NULL;
182 TXMLNode * prevNode = xmlNode;
190 // -- Get hostname and port from TDS node out of XML
191 while ( ( attrNode = prevNode->GetNextNode() ) ) {
194 // -- Get port out of the commandline
195 if ( strcmp( attrNode->GetNodeName(), "Cmd" ) == 0 ) {
196 TString cmd( attrNode->GetText() );
198 TObjArray * cmdTok = cmd.Tokenize(" ");
199 xmlPort = ((TObjString*) cmdTok->At(2))->GetString();
202 else if ( strcmp( attrNode->GetNodeName(), "Node" ) == 0 )
203 xmlHostname = attrNode->GetText();
205 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
207 TString xmlNodename = GetNodename( xmlHostname );
209 // -- Resolve hostname and port information --
210 iResult = fSrcTranslator->Translate( xmlNodename, xmlPort, hostname, port );
213 { AliError( Form("Error resolving hostname : %s", xmlHostname.Data()) ); }
214 else if ( iResult == 2 )
215 { AliError( Form("Error resolving port : %s", xmlPort.Data()) ); }
219 // -- Reset loop to TDS node
222 // -- Get Sources out of XML, resolve sources, add to sources List
223 while ( ( attrNode = prevNode->GetNextNode() ) ) {
226 // Find only "Parent" tags, otherwise continue to next tag
227 if ( strcmp( attrNode->GetNodeName(), "Parent" ) != 0 )
230 TString xmlParent = attrNode->GetText();
233 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc( hostname, port );
235 if ( FillSourceInformation( xmlParent, source ) ) {
236 AliError( Form("Error resolving source : %s", xmlParent.Data()) );
241 fSourceList->Add( source );
243 AliInfo( Form("New Source added : %s", xmlParent.Data()) );
247 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
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
261 if ( ! xmlParent.Contains( "_" ) ) {
262 AliError( Form("Source %s could not be resolved", xmlParent.Data() ) );
268 // -- Get detector / subDetector / subSubDetector
269 TObjArray * parentTokens = xmlParent.Tokenize("_");
270 Int_t nParentTokens = parentTokens->GetEntries();
272 TString detector = ((TObjString*) parentTokens->At(0) )->GetString();
273 TString subDetector = "";
274 TString subSubDetector = "";
275 TString name = ((TObjString*) parentTokens->At(1) )->GetString();
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();
284 // -- Apply detector corrections
285 fSrcTranslator->ApplyDetectorCorrections( detector, subDetector );
287 // -- Remove Leading '0' in sub detector and subsubdetector
288 subDetector.Remove( TString::kLeading, '0' );
289 subSubDetector.Remove( TString::kLeading, '0' );
291 // -- Set detector / subDetector / subSubDetector
292 // source->SetDetectors( detector, subDetector, subSubDetector );
294 // -- Fill dataType / specification / className
295 iResult = fSrcTranslator->FillSourceDesc( source, name );
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()) );
307 //##################################################################################
308 TString AliEveHOMERXMLHandler::GetNodename( TString xmlHostname ) {
309 // Get xml nodename out of xml hostname
313 TXMLNode * node = NULL;
314 TXMLNode * prevNode = fRootNode->GetChildren();
316 while ((node = prevNode->GetNextNode()) != 0)
320 // -- Find only "Node" nodes, otherwise continue
321 if ( strcmp( node->GetNodeName(), "Node" ) != 0 )
324 // -- Get Attributes of current node
325 TList *attrList = node->GetAttributes();
327 TIter next(attrList);
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();
339 // -- if this is not the correct "nodeID" continue
340 if ( nodeId != xmlHostname )
345 } // while ( node = prevNode->GetNextNode() ) {