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 HLT configuration description for a single component.
23 // @note The class is used in Offline (AliRoot) context
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()
55 fListSrcElementIdx(-1),
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
68 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources,
69 const char* arguments, const char* bufsize)
72 fComponent(component),
73 fStringSources(sources),
76 fListSrcElementIdx(-1),
77 fArguments(arguments),
82 // see header file for function documentation
83 if (bufsize) fBufferSize=ConvertSizeString(bufsize);
84 if (id && component) {
85 if (fgConfigurationHandler) {
86 fgConfigurationHandler->RegisterConfiguration(this);
88 HLTWarning("no configuration handler set, skip registration");
93 AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
98 fComponent(src.fComponent),
99 fStringSources(src.fStringSources),
102 fListSrcElementIdx(-1),
103 fArguments(src.fArguments),
106 fBufferSize(src.fBufferSize)
108 // see header file for function documentation
111 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
113 // see header file for function documentation
114 if (this==&src) return *this;
117 fComponent=src.fComponent;
118 fStringSources=src.fStringSources;
120 fArguments=src.fArguments;
123 fBufferSize=src.fBufferSize;
127 AliHLTConfiguration::~AliHLTConfiguration()
129 // see header file for function documentation
130 if (fgConfigurationHandler) {
131 if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) {
132 // remove the configuration from the handler if it exists
133 // but DO NOT remove the clone configuration
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 (fListSrcElementIdx>=0 && fListSrcElementIdx<(int)fListSources.size() &&
196 strcmp(id, (fListSources[fListSrcElementIdx])->GetName())==0) {
197 pSrc=fListSources[fListSrcElementIdx];
201 pSrc=GetFirstSource();
203 if (strcmp(id, pSrc->GetName())==0)
205 pSrc=GetNextSource();
212 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() const
214 // see header file for function documentation
215 AliHLTConfiguration* pSrc=NULL;
217 const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx=-1;
218 pSrc=GetNextSource();
223 AliHLTConfiguration* AliHLTConfiguration::GetNextSource() const
225 // see header file for function documentation
226 AliHLTConfiguration* pSrc=NULL;
228 if (fListSrcElementIdx+1<(int)fListSources.size()) {
229 const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx++;
230 pSrc=fListSources[fListSrcElementIdx];
236 int AliHLTConfiguration::SourcesResolved() const
238 // see header file for function documentation
240 if (fNofSources>=0) {
241 iResult=fNofSources==(int)fListSources.size();
246 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
248 // see header file for function documentation
251 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
252 while (element!=fListSources.end()) {
253 if (*element==pConf) {
254 fListSources.erase(element);
255 fListSrcElementIdx=fListSources.size();
256 // there is no need to re-evaluate until there was a new configuration registered
257 // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
258 //InvalidateSources();
269 void AliHLTConfiguration::PrintStatus() const
271 // see header file for function documentation
272 HLTLogKeyword("configuration status");
273 HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
274 if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data());
275 else HLTMessage(" - component string invalid");
276 if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data());
277 else HLTMessage(" - no sources");
278 if (SourcesResolved()!=1)
279 HLTMessage(" there are unresolved sources");
280 AliHLTConfiguration* pSrc=GetFirstSource();
282 HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
283 pSrc=GetNextSource();
287 void AliHLTConfiguration::Print(const char* option) const
290 if (option && strcmp(option, "status")==0) {
294 HLTLogKeyword("configuration");
295 HLTMessage("configuration %s: component %s, sources %s, arguments %s",
299 GetArgumentSettings()
303 int AliHLTConfiguration::GetArguments(const char*** pArgv) const
305 // see header file for function documentation
309 if ((iResult=const_cast<AliHLTConfiguration*>(this)->ExtractArguments())<0) {
310 HLTError("error extracting arguments for configuration %s", GetName());
312 } else if (fArgc<0) {
313 HLTError("previous argument extraction failed");
315 //HLTDebug("%s fArgc %d", GetName(), fArgc);
317 *pArgv=(const char**)fArgv;
319 HLTError("invalid parameter");
326 int AliHLTConfiguration::ExtractSources()
328 // see header file for function documentation
330 fNofSources=0; // indicates that the function was called, there are either n or 0 sources
331 fListSources.clear();
332 if (!fgConfigurationHandler) {
333 HLTError("global configuration handler not initialized, can not resolve sources");
336 if (!fStringSources.IsNull()) {
337 vector<char*> tgtList;
338 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
339 fNofSources=tgtList.size();
340 vector<char*>::iterator element=tgtList.begin();
341 while ((element=tgtList.begin())!=tgtList.end()) {
342 AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
344 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
345 fListSources.push_back(pConf);
347 HLTError("can not find source \"%s\"", (*element));
351 tgtList.erase(element);
355 fListSrcElementIdx=-1;
356 return iResult<0?iResult:SourcesResolved();
359 int AliHLTConfiguration::ExtractArguments()
361 // see header file for function documentation
363 if (!fArguments.IsNull()) {
364 vector<char*> tgtList;
365 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
366 fArgc=tgtList.size();
367 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
369 fArgv = new char*[fArgc];
371 vector<char*>::iterator element=tgtList.begin();
373 while (element!=tgtList.end()) {
374 //HLTDebug("assign arguments %d (%s)", i, *element);
375 fArgv[i++]=(*element);
384 // there are zero arguments
387 if (iResult<0) fArgc=iResult;
391 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
393 // see header file for function documentation
396 //HLTDebug("interprete \"%s\"", arg);
401 //HLTDebug("%d %x", i, arg[i]);
402 if (arg[i]=='\'' && bQuote==0) {
404 } else if (arg[i]==0 ||
405 (arg[i]==' ' && bQuote==0) ||
406 (arg[i]=='\'' && bQuote==1)) {
409 char* pEntry= new char[i-prec+1];
411 strncpy(pEntry, &arg[prec], i-prec);
412 pEntry[i-prec]=0; // terminate string
413 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
414 argList.push_back(pEntry);
419 } else if (prec==-1) prec=i;
420 } while (arg[i++]!=0 && iResult>=0);
427 int AliHLTConfiguration::ConvertSizeString(const char* strSize) const
429 // see header file for function documentation
431 if (!strSize) return -1;
434 size=strtol(strSize, &endptr, 10);
437 if (endptr==strSize) {
438 HLTWarning("ignoring unrecognized buffer size '%s'", strSize);
440 } else if (*endptr==0) {
442 } else if (*endptr=='k') {
444 } else if (*endptr=='M') {
447 HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]);
450 HLTWarning("ignoring negative buffer size specifier '%s'", strSize);
457 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
459 // see header file for function documentation
462 AliHLTConfiguration* pDep=NULL;
463 if ((pDep=GetSource(id))!=NULL) {
464 if (pTgtList) pTgtList->Add(pDep);
467 pDep=GetFirstSource();
468 while (pDep && iResult==0) {
469 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
470 if (pTgtList) pTgtList->AddFirst(pDep);
473 pDep=GetNextSource();