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 // remove the configuration from the handler if it exists
135 // but DO NOT remove the clone configuration
136 fgConfigurationHandler->RemoveConfiguration(this);
141 for (int i=0; i<fArgc; i++) {
149 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
150 while (element!=fListSources.end()) {
151 fListSources.erase(element);
152 element=fListSources.begin();
156 /* the global configuration handler which is used to automatically register the configuration
158 AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL;
160 int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
162 // see header file for function documentation
164 if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
165 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler);
167 fgConfigurationHandler=pHandler;
171 int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler)
173 // see header file for function documentation
175 if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
176 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler);
179 fgConfigurationHandler=NULL;
183 const char* AliHLTConfiguration::GetName() const
185 // see header file for function documentation
188 return TObject::GetName();
191 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
193 // see header file for function documentation
194 AliHLTConfiguration* pSrc=NULL;
196 // first check the current element
197 if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
198 pSrc=*fListSrcElement;
202 pSrc=GetFirstSource();
204 if (strcmp(id, pSrc->GetName())==0)
206 pSrc=GetNextSource();
213 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
215 // see header file for function documentation
216 AliHLTConfiguration* pSrc=NULL;
217 if (fNofSources>=0 || ExtractSources()>=0) {
218 fListSrcElement=fListSources.begin();
219 if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
224 AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
226 // see header file for function documentation
227 AliHLTConfiguration* pSrc=NULL;
229 if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end())
230 pSrc=*fListSrcElement;
235 int AliHLTConfiguration::SourcesResolved(int bAuto)
237 // see header file for function documentation
239 if (fNofSources>=0 || (bAuto && (iResult=ExtractSources()))>=0) {
240 //HLTDebug("fNofSources=%d", fNofSources);
241 //HLTDebug("list size = %d", fListSources.size());
242 iResult=fNofSources==(int)fListSources.size();
247 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
249 // see header file for function documentation
252 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
253 while (element!=fListSources.end()) {
254 if (*element==pConf) {
255 fListSources.erase(element);
256 fListSrcElement=fListSources.end();
257 // there is no need to re-evaluate until there was a new configuration registered
258 // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
259 //InvalidateSources();
270 void AliHLTConfiguration::PrintStatus()
272 // see header file for function documentation
273 HLTLogKeyword("configuration status");
274 HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
275 if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data());
276 else HLTMessage(" - component string invalid");
277 if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data());
278 else HLTMessage(" - no sources");
279 if (SourcesResolved(1)<=0)
280 HLTMessage(" there are unresolved sources");
281 AliHLTConfiguration* pSrc=GetFirstSource();
283 HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
284 pSrc=GetNextSource();
288 int AliHLTConfiguration::GetArguments(const char*** pArgv)
290 // see header file for function documentation
294 if ((iResult=ExtractArguments())<0) {
295 HLTError("error extracting arguments for configuration %s", GetName());
298 } else if (fArgc<0) {
299 HLTError("previous argument extraction failed");
301 //HLTDebug("%s fArgc %d", GetName(), fArgc);
303 *pArgv=(const char**)fArgv;
305 HLTError("invalid parameter");
312 int AliHLTConfiguration::ExtractSources()
314 // see header file for function documentation
317 if (!fStringSources.IsNull()) {
318 vector<char*> tgtList;
319 fListSources.clear();
320 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
321 fNofSources=tgtList.size();
322 vector<char*>::iterator element=tgtList.begin();
323 while ((element=tgtList.begin())!=tgtList.end()) {
324 if (fgConfigurationHandler) {
325 AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
327 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
328 fListSources.push_back(pConf);
330 HLTError("can not find source \"%s\"", (*element));
333 } else if (iResult>=0) {
335 HLTFatal("global configuration handler not initialized, can not resolve sources");
338 tgtList.erase(element);
340 fListSrcElement=fListSources.begin();
346 int AliHLTConfiguration::ExtractArguments()
348 // see header file for function documentation
350 if (!fArguments.IsNull()) {
351 vector<char*> tgtList;
352 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
353 fArgc=tgtList.size();
354 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
356 fArgv = new char*[fArgc];
358 vector<char*>::iterator element=tgtList.begin();
360 while (element!=tgtList.end()) {
361 //HLTDebug("assign arguments %d (%s)", i, *element);
362 fArgv[i++]=(*element);
371 // there are zero arguments
377 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
379 // see header file for function documentation
382 //HLTDebug("interprete \"%s\"", arg);
387 //HLTDebug("%d %x", i, arg[i]);
388 if (arg[i]=='\'' && bQuote==0) {
390 } else if (arg[i]==0 ||
391 (arg[i]==' ' && bQuote==0) ||
392 (arg[i]=='\'' && bQuote==1)) {
395 char* pEntry= new char[i-prec+1];
397 strncpy(pEntry, &arg[prec], i-prec);
398 pEntry[i-prec]=0; // terminate string
399 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
400 argList.push_back(pEntry);
405 } else if (prec==-1) prec=i;
406 } while (arg[i++]!=0 && iResult>=0);
413 int AliHLTConfiguration::ConvertSizeString(const char* strSize) const
415 // see header file for function documentation
417 if (!strSize) return -1;
420 size=strtol(strSize, &endptr, 10);
423 if (endptr==strSize) {
424 HLTWarning("ignoring unrecognized buffer size '%s'", strSize);
426 } else if (*endptr==0) {
428 } else if (*endptr=='k') {
430 } else if (*endptr=='M') {
433 HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]);
436 HLTWarning("ignoring negative buffer size specifier '%s'", strSize);
443 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
445 // see header file for function documentation
448 AliHLTConfiguration* pDep=NULL;
449 if ((pDep=GetSource(id))!=NULL) {
450 if (pTgtList) pTgtList->Add(pDep);
453 pDep=GetFirstSource();
454 while (pDep && iResult==0) {
455 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
456 if (pTgtList) pTgtList->AddFirst(pDep);
459 pDep=GetNextSource();