3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
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 AliHLTConfiguration.cxx
20 @author Matthias Richter
22 @brief Implementation of HLT configurations.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
36 #include "AliHLTConfiguration.h"
37 #include "AliHLTConfigurationHandler.h"
38 #include "AliHLTTask.h"
39 #include "AliHLTComponent.h"
40 #include "AliHLTComponentHandler.h"
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTConfiguration)
48 AliHLTConfiguration::AliHLTConfiguration()
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 fListSrcElement=fListSources.begin();
70 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources,
71 const char* arguments, const char* bufsize)
74 fComponent(component),
75 fStringSources(sources),
79 fArguments(arguments),
84 // see header file for function documentation
85 if (bufsize) fBufferSize=ConvertSizeString(bufsize);
86 fListSrcElement=fListSources.begin();
87 if (id && component) {
88 if (fgConfigurationHandler) {
89 fgConfigurationHandler->RegisterConfiguration(this);
91 HLTError("no configuration handler set, abort registration");
96 AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
101 fComponent(src.fComponent),
102 fStringSources(src.fStringSources),
106 fArguments(src.fArguments),
109 fBufferSize(src.fBufferSize)
111 // see header file for function documentation
112 fListSrcElement=fListSources.begin();
115 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
117 // see header file for function documentation
119 fComponent=src.fComponent;
120 fStringSources=src.fStringSources;
122 fArguments=src.fArguments;
125 fBufferSize=src.fBufferSize;
129 AliHLTConfiguration::~AliHLTConfiguration()
131 // see header file for function documentation
132 if (fgConfigurationHandler) {
133 if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) {
134 fgConfigurationHandler->RemoveConfiguration(this);
139 for (int i=0; i<fArgc; i++) {
147 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
148 while (element!=fListSources.end()) {
149 fListSources.erase(element);
150 element=fListSources.begin();
154 /* the global configuration handler which is used to automatically register the configuration
156 AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL;
158 int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
160 // see header file for function documentation
162 if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
163 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler);
165 fgConfigurationHandler=pHandler;
169 int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler)
171 // see header file for function documentation
173 if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
174 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler);
177 fgConfigurationHandler=NULL;
181 const char* AliHLTConfiguration::GetName() const
183 // see header file for function documentation
186 return TObject::GetName();
189 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
191 // see header file for function documentation
192 AliHLTConfiguration* pSrc=NULL;
194 // first check the current element
195 if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
196 pSrc=*fListSrcElement;
200 pSrc=GetFirstSource();
202 if (strcmp(id, pSrc->GetName())==0)
204 pSrc=GetNextSource();
211 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
213 // see header file for function documentation
214 AliHLTConfiguration* pSrc=NULL;
215 if (fNofSources>=0 || ExtractSources()>=0) {
216 fListSrcElement=fListSources.begin();
217 if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
222 AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
224 // see header file for function documentation
225 AliHLTConfiguration* pSrc=NULL;
227 if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end())
228 pSrc=*fListSrcElement;
233 int AliHLTConfiguration::SourcesResolved(int bAuto)
235 // see header file for function documentation
237 if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) {
238 //HLTDebug("fNofSources=%d", fNofSources);
239 //HLTDebug("list size = %d", fListSources.size());
240 iResult=fNofSources==(int)fListSources.size();
245 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
247 // see header file for function documentation
250 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
251 while (element!=fListSources.end()) {
252 if (*element==pConf) {
253 fListSources.erase(element);
254 fListSrcElement=fListSources.end();
255 // there is no need to re-evaluate until there was a new configuration registered
256 // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
257 //InvalidateSources();
268 void AliHLTConfiguration::PrintStatus()
270 // see header file for function documentation
271 HLTLogKeyword("configuration status");
272 HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
273 if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data());
274 else HLTMessage(" - component string invalid");
275 if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data());
276 else HLTMessage(" - no sources");
277 if (SourcesResolved(1)<=0)
278 HLTMessage(" there are unresolved sources");
279 AliHLTConfiguration* pSrc=GetFirstSource();
281 HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
282 pSrc=GetNextSource();
286 int AliHLTConfiguration::GetArguments(const char*** pArgv)
288 // see header file for function documentation
292 if ((iResult=ExtractArguments())<0) {
293 HLTError("error extracting arguments for configuration %s", GetName());
296 } else if (fArgc<0) {
297 HLTError("previous argument extraction failed");
299 //HLTDebug("%s fArgc %d", GetName(), fArgc);
301 *pArgv=(const char**)fArgv;
303 HLTError("invalid parameter");
310 int AliHLTConfiguration::ExtractSources()
312 // see header file for function documentation
315 if (!fStringSources.IsNull()) {
316 vector<char*> tgtList;
317 fListSources.clear();
318 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
319 fNofSources=tgtList.size();
320 vector<char*>::iterator element=tgtList.begin();
321 while ((element=tgtList.begin())!=tgtList.end()) {
322 if (fgConfigurationHandler) {
323 AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
325 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
326 fListSources.push_back(pConf);
328 HLTError("can not find source \"%s\"", (*element));
331 } else if (iResult>=0) {
333 HLTFatal("global configuration handler not initialized, can not resolve sources");
336 tgtList.erase(element);
338 fListSrcElement=fListSources.begin();
344 int AliHLTConfiguration::ExtractArguments()
346 // see header file for function documentation
348 if (!fArguments.IsNull()) {
349 vector<char*> tgtList;
350 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
351 fArgc=tgtList.size();
352 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
354 fArgv = new char*[fArgc];
356 vector<char*>::iterator element=tgtList.begin();
358 while (element!=tgtList.end()) {
359 //HLTDebug("assign arguments %d (%s)", i, *element);
360 fArgv[i++]=(*element);
369 // there are zero arguments
375 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList) const
377 // see header file for function documentation
380 //HLTDebug("interprete \"%s\"", arg);
385 //HLTDebug("%d %x", i, arg[i]);
386 if (arg[i]=='\'' && bQuote==0) {
388 } else if (arg[i]==0 ||
389 (arg[i]==' ' && bQuote==0) ||
390 (arg[i]=='\'' && bQuote==1)) {
393 char* pEntry= new char[i-prec+1];
395 strncpy(pEntry, &arg[prec], i-prec);
396 pEntry[i-prec]=0; // terminate string
397 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
398 argList.push_back(pEntry);
403 } else if (prec==-1) prec=i;
404 } while (arg[i++]!=0 && iResult>=0);
411 int AliHLTConfiguration::ConvertSizeString(const char* strSize) const
413 // see header file for function documentation
415 if (!strSize) return -1;
418 size=strtol(strSize, &endptr, 10);
421 if (endptr==strSize) {
422 HLTWarning("ignoring unrecognized buffer size '%s'", strSize);
424 } else if (*endptr==0) {
426 } else if (*endptr=='k') {
428 } else if (*endptr=='M') {
431 HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]);
434 HLTWarning("ignoring negative buffer size specifier '%s'", strSize);
441 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
443 // see header file for function documentation
446 AliHLTConfiguration* pDep=NULL;
447 if ((pDep=GetSource(id))!=NULL) {
448 if (pTgtList) pTgtList->Add(pDep);
451 pDep=GetFirstSource();
452 while (pDep && iResult==0) {
453 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
454 if (pTgtList) pTgtList->AddFirst(pDep);
457 pDep=GetNextSource();