3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
8 //* for The ALICE HLT Project. *
10 //* Permission to use, copy, modify and distribute this software and its *
11 //* documentation strictly for non-commercial purposes is hereby granted *
12 //* without fee, provided that the above copyright notice appears in all *
13 //* copies and that both the copyright notice and this permission notice *
14 //* appear in the supporting documentation. The authors make no claims *
15 //* about the suitability of this software for any purpose. It is *
16 //* provided "as is" without express or implied warranty. *
17 //**************************************************************************
19 /// @file AliHLTOnlineConfiguration.h
20 /// @author Matthias Richter
21 /// @author Lars Christian Raae
23 /// @brief Description of the HLT online configuration
30 #include <TDOMParser.h>
34 #include <TObjString.h>
36 #include "AliHLTConfigurationHandler.h"
37 #include "AliHLTDAQ.h"
38 #include "AliHLTOnlineConfiguration.h"
39 #include "AliHLTComponentConfiguration.h"
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTOnlineConfiguration)
44 AliHLTOnlineConfiguration::AliHLTOnlineConfiguration()
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliHLTOnlineConfiguration::~AliHLTOnlineConfiguration()
64 int AliHLTOnlineConfiguration::LoadConfiguration(const char* filename)
66 /// load configuration from file
76 in.seekg(0, std::ios::end );
77 filesize = in.tellg();
78 in.seekg(0, std::ios::beg);
80 char * content = new char[filesize];
81 in.read(content, filesize);
84 fXMLBuffer.Adopt(filesize, content);
91 int AliHLTOnlineConfiguration::Compress()
93 /// compress the xml buffer
98 int AliHLTOnlineConfiguration::Uncompress()
100 /// compress the xml buffer
105 int AliHLTOnlineConfiguration::Parse()
107 /// parse the xml buffer
110 if (TestBit(kLoaded) && !TestBit(kParsed)) {
112 TDOMParser *domParser = new TDOMParser();
113 domParser->SetValidate(false);
114 Int_t parsecode = domParser->ParseBuffer(fXMLBuffer.GetArray(), fXMLSize);
116 HLTError("Configuration XML invalid or not well-formed (error code %d)", parsecode);
120 if ((doc = domParser->GetXMLDocument()) && doc->GetRootNode()) {
121 AliHLTConfigurationHandler* pHandler = AliHLTConfigurationHandler::Instance();
122 pHandler->Deactivate(true);
123 iResult = ParseConfiguration(doc->GetRootNode());
127 pHandler->ClearScheduledRegistrations();
128 fConfEntryList.Delete();
129 fDefaultChains.Clear();
131 pHandler->Activate();
141 int AliHLTOnlineConfiguration::ParseConfiguration(TXMLNode* node)
143 /// parse xml configuration
147 if (node && node->GetChildren()) {
148 node = node->GetChildren();
149 for (; node && iResult == 0; node = node->GetNextNode()) {
150 if (node->GetNodeType() == TXMLNode::kXMLElementNode) {
151 if (strcmp(node->GetNodeName(), "Proc") == 0) {
153 const char* type = 0;
154 if (node->HasAttributes()) {
155 TList* attrList = node->GetAttributes();
157 TIter next(attrList);
158 while ((attr=(TXMLAttr*)next()))
159 if (strcmp(attr->GetName(), "ID") == 0) {
160 id = attr->GetValue();
161 } else if (strcmp(attr->GetName(), "type") == 0) {
162 type = attr->GetValue();
165 if (id && type && node->GetChildren()) {
166 iResult = ParseEntry(node->GetChildren(), id, type);
173 HLTError("Configuration component missing ID attribute");
176 HLTError("Configuration component missing type attribute");
179 HLTError("Empty configuration component %s", id);
186 HLTError("An error occurred parsing the configuration. Aborting...");
190 HLTError("Configuration did not contain any (valid) elements");
195 HLTError("Configuration was empty");
200 int AliHLTOnlineConfiguration::ParseEntry(TXMLNode* node, const char* id,
203 /// Parse XML configuration entry.
207 const char* source = 0;
210 for (; node; node = node->GetNextNode()) {
211 if (node->GetNodeType() == TXMLNode::kXMLElementNode) {
212 if (strcmp(node->GetNodeName(), "Cmd") == 0) {
213 if (!cmd) // Use only the first (non-empty) <Cmd> element
214 cmd = node->GetText();
216 else if (strcmp(node->GetNodeName(), "Node") == 0) {
217 if (!nodes.IsNull()) nodes += " "; nodes += node->GetText();
219 else if (strcmp(node->GetNodeName(), "Parent") == 0) {
220 source = node->GetText();
221 if (sources.Contains(source)) {
223 HLTError("Configuration component %s has duplicate <Parent> element %s",
227 if (!sources.IsNull()) sources += " "; sources += node->GetText();
235 HLTError("Configuration component %s does not contain <Cmd> element", id);
237 else if (cmd == strstr(cmd, "AliRootWrapperSubscriber"))
238 iResult = ParseStandardComponent(id, type, cmd, sources, nodes);
239 else if (cmd == strstr(cmd, "RORCPublisher"))
240 iResult = ParseRORCPublisher(id, type, cmd, sources, nodes);
241 else if (cmd == strstr(cmd, "TCPDumpSubscriber"))
242 iResult = ParseTCPDumpSubscriber(id, type, cmd, sources, nodes);
243 else if (cmd == strstr(cmd, "Relay"))
244 iResult = ParseRelay(id, type, cmd, sources, nodes);
245 else if (cmd == strstr(cmd, "HLTOutFormatter"))
246 iResult = ParseHLTOutFormatter(id, type, cmd, sources, nodes);
247 else if (cmd == strstr(cmd, "HLTOutWriterSubscriber"))
248 iResult = ParseHLTOutWriterSubscriber(id, type, cmd, sources, nodes);
251 HLTError("Configuration component %s contains unknown <Cmd> element", id);
258 int AliHLTOnlineConfiguration::ParseStandardComponent(const char* id,
259 const char* type, const char* cmd, TString& sources, TString& nodes)
261 /// Parse standard component configuration
264 if (strcmp(type, "prc") != 0) {
266 HLTError("Configuration component %s has invalid type %s (expected prc)",
270 // Parse component command
271 const char* compid="";
272 const char* complib="";
274 bool hasArgs = false;
275 char* cmdcopy = new char[strlen(cmd)+1];
276 if (!cmdcopy) return -ENOMEM;
277 cmdcopy[strlen(cmd)]=0;
278 strncpy(cmdcopy, cmd, strlen(cmd));
279 strtok(cmdcopy, " -"); // Skip "AliRootWrapperSubscriber"
281 bool CFTransform = false;
282 while (((strtmp = strtok(0, " -")))) {
283 if (strcmp(strtmp, "componentid") == 0) {
284 compid = strtok(0, " -");
285 if (strcmp(compid, "TPCHWClusterTransform") == 0)
286 // FIXME: Ugly hack to replace cluster transformers. Refactor.
289 else if (strcmp(strtmp, "componentargs") == 0)
291 else if (strcmp(strtmp, "componentlibrary") == 0)
292 complib = strtok(0, " -");
295 compid = "TPCClusterFinder32Bit";
296 // NOTE: Cluster transformer's arguments ignored and cluster finder
297 // component gets no arguments at all...
301 // Parse component arguments
302 int start = strstr(cmd, "-componentargs") + strlen("-componentargs") + 2
304 int arglen = strcspn(cmd+start, "\"");
305 // Verify that we have the actual limits of the componentargs
306 if ((size_t)(start+arglen) < strlen(cmd) && cmd[start-1] == '\"' &&
307 cmd[start+arglen] == '\"')
309 compargs = new char[arglen+1];
310 strncpy(compargs, cmd + start, arglen);
311 compargs[arglen] = '\0';
316 HLTError("Configuration component %s is missing component id", id);
320 HLTError("Configuration component %s is missing component library", id);
322 if (hasArgs && !compargs) {
324 HLTError("Configuration component %s is missing component arguments", id);
327 AliHLTComponentConfiguration* entry = new AliHLTComponentConfiguration(id,
328 compid, sources.Data(), compargs);
329 entry->SetOnlineCommand(cmd);
330 entry->SetComponentLibrary(complib);
331 entry->SetNodeNames(nodes.Data());
332 fConfEntryList.Add(entry);
340 int AliHLTOnlineConfiguration::ParseRORCPublisher(const char* id,
341 const char* type, const char* cmd, TString& sources, TString& nodes)
343 /// Parse RORCPublisher configuration
346 if (strcmp(type, "src") != 0) {
348 HLTError("Configuration component %s has invalid type %s (expected src)",
352 const char compid[] = "AliRawReaderPublisher";
353 const char complib[] = "libAliHLTUtil.so";
354 // Parse (and validate) component command
357 if (strstr(cmd, "-hwcoproc")) {
358 // HW Co-processor has complex argument rules, so skip full validation
359 const char* key=strstr(cmd, "-ddlid");
361 res = sscanf(key, "-ddlid %d", &ddlID);
365 res = sscanf(cmd, "RORCPublisher -slot %*d %*d %*d %*d -rorcinterface %*d -sleep "
366 "-sleeptime %*d -maxpendingevents %*d -alicehlt -ddlid %d", &ddlID);
370 HLTError("Configuration component %s has <Cmd> element of unknown format\n"
371 "Expected format: RORCPublisher -slot %%d %%d %%d %%d -rorcinterface %%d "
372 "-sleep -sleeptime %%d -maxpendingevents %%d -alicehlt -ddlid %%d", id);
376 Int_t detectorID = AliHLTDAQ::DetectorIDFromDdlID(ddlID, ddlIndex);
377 string HLTOrigin = AliHLTDAQ::HLTOrigin(detectorID);
378 string HLTSpecification = AliHLTDAQ::HLTSpecificationFromDdlID(ddlID);
380 compargs.Form("-minid %d -datatype 'DDL_RAW ' '%s' -dataspec %s",
381 ddlID, HLTOrigin.c_str(), HLTSpecification.c_str());
382 AliHLTComponentConfiguration* entry = new AliHLTComponentConfiguration(id,
383 compid, sources.Data(), compargs.Data());
384 entry->SetOnlineCommand(cmd);
385 entry->SetComponentLibrary(complib);
386 entry->SetNodeNames(nodes.Data());
387 fConfEntryList.Add(entry);
393 int AliHLTOnlineConfiguration::ParseTCPDumpSubscriber(const char* id,
394 const char* type, const char* /* cmd */, TString& /* sources */,
395 TString& /* nodes */)
397 /// Parse TCPDumpSubscriber configuration
399 if (strcmp(type, "snk") != 0) {
401 HLTError("Configuration component %s has invalid type %s (expected snk)",
407 int AliHLTOnlineConfiguration::ParseRelay(const char* id, const char* type,
408 const char* cmd, TString& sources, TString& nodes)
410 /// Parse Relay configuration
413 if (strcmp(type, "prc") != 0) {
415 HLTError("Configuration component %s has invalid type %s (expected prc)",
419 const char compid[] = "BlockFilter";
420 const char complib[] = "libAliHLTUtil.so";
421 const char* compargs = "";
422 if (strcmp(cmd, "Relay") == 0) {
423 AliHLTComponentConfiguration* entry = new AliHLTComponentConfiguration(id,
424 compid, sources.Data(), compargs);
425 entry->SetOnlineCommand(cmd);
426 entry->SetComponentLibrary(complib);
427 entry->SetNodeNames(nodes.Data());
428 fConfEntryList.Add(entry);
432 HLTError("Configuration component %s has <Cmd> element of unknown type "
439 int AliHLTOnlineConfiguration::ParseHLTOutFormatter(const char* id,
440 const char* type, const char* /* cmd */, TString& sources,
441 TString& /* nodes */)
443 /// Parse HLTOutFormatter configuration
446 if (strcmp(type, "prc") != 0) {
448 HLTError("Configuration component %s has invalid type %s (expected prc)",
452 fDefaultChains = sources;
457 int AliHLTOnlineConfiguration::ParseHLTOutWriterSubscriber(const char* id,
458 const char* type, const char* /* cmd */, TString& /* sources */,
459 TString& /* nodes */)
461 /// Parse HLTOutWriterSubscriber configuration
464 if (strcmp(type, "snk") != 0) {
466 HLTError("Configuration component %s has invalid type %s (expected snk)",
472 TString AliHLTOnlineConfiguration::GetComponentLibraries()
474 /// get component libraries
477 AliHLTComponentConfiguration* pConf;
479 TIter next(&fConfEntryList);
480 while ((pConf=(AliHLTComponentConfiguration*)next())) {
481 complib = pConf->GetComponentLibrary();
482 if (!result.Contains(complib)) {
483 if (!result.IsNull()) result+=" "; result+=complib;
489 void AliHLTOnlineConfiguration::Print(const char* options) const
491 /// overloaded from TObject, print info
492 const UInt_t defaultSampleSize = 200;
494 TObject::Print(options);
495 printf("Configuration loaded: %s\n", (TestBit(kLoaded) ? "YES" : "NO"));
496 TString opt = options;
498 Bool_t buffer = opt.Contains("buffer");
499 Bool_t parsed = opt.Contains("parsed");
501 if (TestBit(kLoaded)) {
503 char configuration[fXMLSize + 1];
504 strncpy(configuration, fXMLBuffer.GetArray(), fXMLSize);
505 printf("%s\n\n", configuration);
507 AliHLTComponentConfiguration* pConf;
508 TIter next(&fConfEntryList);
509 while ((pConf=(AliHLTComponentConfiguration*)next())) {
510 pConf->Print("status");
513 Int_t sampleSize = (defaultSampleSize <= fXMLSize) ?
514 defaultSampleSize : fXMLSize;
515 char sample[sampleSize];
516 for (int i = 0; i < sampleSize - 1; i++)
517 sample[i] = fXMLBuffer.At(i);
518 sample[sampleSize - 1] = '\0';
519 printf("%s...\n\n", sample);
523 printf("XML size (uncompressed): %d\n", fXMLSize);
524 printf("Configuration compressed: %s\n", (TestBit(kCompressed) ? "YES" : "NO"));
525 printf("Configuration parsed: %s\n", (TestBit(kParsed) ? "YES" : "NO"));
526 printf("Parsed configuration entries: %d\n", fConfEntryList.GetSize());
527 printf("Default chains: %s\n", fDefaultChains.Data());
530 void AliHLTOnlineConfiguration::Dump() const
532 /// overloaded from TObject, more crude data dump
537 void AliHLTOnlineConfiguration::Clear(Option_t * option)
539 /// overloaded from TObject, clear object
541 TObject::Clear(option);
542 fConfEntryList.Delete();
543 fDefaultChains.Clear();
547 ResetBit(kCompressed);
551 TObject * AliHLTOnlineConfiguration::Clone(const char *newname) const
553 /// overloaded from TObject, clone object
555 return TObject::Clone(newname);
558 void AliHLTOnlineConfiguration::Copy(TObject &object) const
560 /// overloaded from TObject, copy object
562 TObject::Copy(object);
565 void AliHLTOnlineConfiguration::Draw(Option_t */*option*/)
567 /// overloaded from TObject, draw graph of the configuration