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;
184 TString xmlHostname = 0;
187 TString hostname = 0;
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();
232 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc( hostname, port );
234 if ( FillSourceInformation( xmlParent, source ) ) {
235 AliError( Form("Error resolving source : %s", xmlParent.Data()) );
240 fSourceList->Add( source );
242 AliInfo( Form("New Source added : %s", xmlParent.Data()) );
246 } // while ( ( attrNode = prevNode->GetNextNode() ) ) {
251 //##################################################################################
252 Int_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
260 if ( ! xmlParent.Contains( "_" ) ) {
261 AliError( Form("Source %s could not be resolved", xmlParent.Data() ) );
267 // -- Get detector / subDetector / subSubDetector
268 TObjArray * parentTokens = xmlParent.Tokenize("_");
269 Int_t nParentTokens = parentTokens->GetEntries();
271 TString detector = ((TObjString*) parentTokens->At(0) )->GetString();
272 TString subDetector = "";
273 TString subSubDetector = "";
274 TString name = ((TObjString*) parentTokens->At(1) )->GetString();
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();
283 // -- Apply detector corrections
284 fSrcTranslator->ApplyDetectorCorrections( detector, subDetector );
286 // -- Remove Leading '0' in sub detector and subsubdetector
287 subDetector.Remove( TString::kLeading, '0' );
288 subSubDetector.Remove( TString::kLeading, '0' );
290 // -- Set detector / subDetector / subSubDetector
291 source->SetDetectors( detector, subDetector, subSubDetector );
293 // -- Fill dataType / specification / className
294 iResult = fSrcTranslator->FillSourceDesc( source, name );
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()) );
306 //##################################################################################
307 TString AliEveHOMERXMLHandler::GetNodename( TString xmlHostname ) {
308 // Get xml nodename out of xml hostname
310 TString nodename = 0;
312 TXMLNode * node = NULL;
313 TXMLNode * prevNode = fRootNode->GetChildren();
315 while ( node = prevNode->GetNextNode() ) {
318 // -- Find only "Node" nodes, otherwise continue
319 if ( strcmp( node->GetNodeName(), "Node" ) != 0 )
322 // -- Get Attributes of current node
323 TList *attrList = node->GetAttributes();
325 TIter next(attrList);
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();
337 // -- if this is not the correct "nodeID" continue
338 if ( nodeId != xmlHostname )
343 } // while ( node = prevNode->GetNextNode() ) {