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()
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 fListSrcElement=fListSources.begin();
69 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
72 fComponent(component),
73 fStringSources(sources),
77 fArguments(arguments),
81 // see header file for function documentation
82 fListSrcElement=fListSources.begin();
83 if (id && component) {
84 if (fgConfigurationHandler) {
85 fgConfigurationHandler->RegisterConfiguration(this);
87 HLTError("no configuration handler set, abort registration");
92 AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
97 fComponent(src.fComponent),
98 fStringSources(src.fStringSources),
102 fArguments(src.fArguments),
106 // see header file for function documentation
107 fListSrcElement=fListSources.begin();
110 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
112 // see header file for function documentation
114 fComponent=src.fComponent;
115 fStringSources=src.fStringSources;
117 fArguments=src.fArguments;
123 AliHLTConfiguration::~AliHLTConfiguration()
125 // see header file for function documentation
126 if (fgConfigurationHandler) {
127 if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) {
128 fgConfigurationHandler->RemoveConfiguration(this);
133 for (int i=0; i<fArgc; i++) {
141 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
142 while (element!=fListSources.end()) {
143 fListSources.erase(element);
144 element=fListSources.begin();
148 /* the global configuration handler which is used to automatically register the configuration
150 AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL;
152 int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
154 // see header file for function documentation
156 if (fgConfigurationHandler!=NULL) {
157 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler);
159 fgConfigurationHandler=pHandler;
163 int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler)
165 // see header file for function documentation
167 if (pHandler!=NULL && fgConfigurationHandler!=pHandler) {
168 fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler);
171 fgConfigurationHandler=NULL;
175 const char* AliHLTConfiguration::GetName() const
177 // see header file for function documentation
180 return TObject::GetName();
183 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
185 // see header file for function documentation
186 AliHLTConfiguration* pSrc=NULL;
188 // first check the current element
189 if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
190 pSrc=*fListSrcElement;
194 pSrc=GetFirstSource();
196 if (strcmp(id, pSrc->GetName())==0)
198 pSrc=GetNextSource();
205 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
207 // see header file for function documentation
208 AliHLTConfiguration* pSrc=NULL;
209 if (fNofSources>=0 || ExtractSources()) {
210 fListSrcElement=fListSources.begin();
211 if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
216 AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
218 // see header file for function documentation
219 AliHLTConfiguration* pSrc=NULL;
221 if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end())
222 pSrc=*fListSrcElement;
227 int AliHLTConfiguration::SourcesResolved(int bAuto)
229 // see header file for function documentation
231 if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) {
232 //HLTDebug("fNofSources=%d", fNofSources);
233 //HLTDebug("list size = %d", fListSources.size());
234 iResult=fNofSources==(int)fListSources.size();
239 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
241 // see header file for function documentation
244 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
245 while (element!=fListSources.end()) {
246 if (*element==pConf) {
247 fListSources.erase(element);
248 fListSrcElement=fListSources.end();
249 // there is no need to re-evaluate until there was a new configuration registered
250 // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
251 //InvalidateSources();
262 void AliHLTConfiguration::PrintStatus()
264 // see header file for function documentation
265 HLTLogKeyword("configuration status");
266 HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
267 if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data());
268 else HLTMessage(" - component string invalid");
269 if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data());
270 else HLTMessage(" - no sources");
271 if (SourcesResolved(1)<=0)
272 HLTMessage(" there are unresolved sources");
273 AliHLTConfiguration* pSrc=GetFirstSource();
275 HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
276 pSrc=GetNextSource();
280 int AliHLTConfiguration::GetArguments(const char*** pArgv)
282 // see header file for function documentation
286 if ((iResult=ExtractArguments())<0) {
287 HLTError("error extracting arguments for configuration %s", GetName());
290 } else if (fArgc<0) {
291 HLTError("previous argument extraction failed");
293 //HLTDebug("%s fArgc %d", GetName(), fArgc);
295 *pArgv=(const char**)fArgv;
297 HLTError("invalid parameter");
304 int AliHLTConfiguration::ExtractSources()
306 // see header file for function documentation
309 if (!fStringSources.IsNull()) {
310 vector<char*> tgtList;
311 fListSources.clear();
312 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
313 fNofSources=tgtList.size();
314 vector<char*>::iterator element=tgtList.begin();
315 while ((element=tgtList.begin())!=tgtList.end()) {
316 if (fgConfigurationHandler) {
317 AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
319 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
320 fListSources.push_back(pConf);
322 HLTError("can not find source \"%s\"", (*element));
325 } else if (iResult>=0) {
327 HLTFatal("global configuration handler not initialized, can not resolve sources");
330 tgtList.erase(element);
332 fListSrcElement=fListSources.begin();
338 int AliHLTConfiguration::ExtractArguments()
340 // see header file for function documentation
342 if (!fArguments.IsNull()) {
343 vector<char*> tgtList;
344 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
345 fArgc=tgtList.size();
346 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
348 fArgv = new char*[fArgc];
350 vector<char*>::iterator element=tgtList.begin();
352 while (element!=tgtList.end()) {
353 //HLTDebug("assign arguments %d (%s)", i, *element);
354 fArgv[i++]=(*element);
363 // there are zero arguments
369 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
371 // see header file for function documentation
374 //HLTDebug("interprete \"%s\"", arg);
379 //HLTDebug("%d %x", i, arg[i]);
380 if (arg[i]=='\'' && bQuote==0) {
382 } else if (arg[i]==0 ||
383 (arg[i]==' ' && bQuote==0) ||
384 (arg[i]=='\'' && bQuote==1)) {
387 char* pEntry= new char[i-prec+1];
389 strncpy(pEntry, &arg[prec], i-prec);
390 pEntry[i-prec]=0; // terminate string
391 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
392 argList.push_back(pEntry);
397 } else if (prec==-1) prec=i;
398 } while (arg[i++]!=0 && iResult>=0);
405 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
407 // see header file for function documentation
410 AliHLTConfiguration* pDep=NULL;
411 if ((pDep=GetSource(id))!=NULL) {
412 if (pTgtList) pTgtList->Add(pDep);
415 pDep=GetFirstSource();
416 while (pDep && iResult==0) {
417 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
418 if (pTgtList) pTgtList->AddFirst(pDep);
421 pDep=GetNextSource();