3 ///**************************************************************************
4 ///* This file is property of and copyright by the *
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
26 #include "AliHLTConfiguration.h"
27 #include "AliHLTConfigurationHandler.h"
28 #include "AliHLTTask.h"
29 #include "AliHLTComponent.h"
30 #include "AliHLTComponentHandler.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTConfiguration)
40 AliHLTConfiguration::AliHLTConfiguration()
47 fListSrcElementIdx(-1),
53 // This class describes a configuration for an HLT component by means of
54 // the following parameters:
55 // - configuration id: a unique id string/name
56 // - component id: id returned by AliHLTComponent::GetComponentID()
57 // - parent configuartions: ids of configurations it requires input from
58 // - component arguments: passed to the component when it is initialized
61 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources,
62 const char* arguments, const char* bufsize)
65 fComponent(component),
66 fStringSources(sources),
69 fListSrcElementIdx(-1),
70 fArguments(arguments),
76 if (bufsize) fBufferSize=ConvertSizeString(bufsize);
77 if (id && component) {
78 if (AliHLTConfigurationHandler::Instance()) {
79 AliHLTConfigurationHandler::Instance()->RegisterConfiguration(this);
81 AliHLTConfigurationHandler::MissedRegistration(id);
86 AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
91 fComponent(src.fComponent),
92 fStringSources(src.fStringSources),
95 fListSrcElementIdx(-1),
96 fArguments(src.fArguments),
99 fBufferSize(src.fBufferSize)
104 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
106 // assignment operator
107 if (this==&src) return *this;
110 fComponent=src.fComponent;
111 fStringSources=src.fStringSources;
113 fArguments=src.fArguments;
116 fBufferSize=src.fBufferSize;
120 AliHLTConfiguration::~AliHLTConfiguration()
123 if (AliHLTConfigurationHandler::Instance()) {
124 if (AliHLTConfigurationHandler::Instance()->FindConfiguration(fID.Data())!=NULL) {
125 // remove the configuration from the handler if it exists
126 // but DO NOT remove the clone configuration
127 AliHLTConfigurationHandler::Instance()->RemoveConfiguration(this);
132 for (int i=0; i<fArgc; i++) {
140 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
141 while (element!=fListSources.end()) {
142 fListSources.erase(element);
143 element=fListSources.begin();
147 const char* AliHLTConfiguration::GetName() const
152 return TObject::GetName();
155 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
158 AliHLTConfiguration* pSrc=NULL;
160 // first check the current element
161 if (fListSrcElementIdx>=0 && fListSrcElementIdx<(int)fListSources.size() &&
162 strcmp(id, (fListSources[fListSrcElementIdx])->GetName())==0) {
163 pSrc=fListSources[fListSrcElementIdx];
167 pSrc=GetFirstSource();
169 if (strcmp(id, pSrc->GetName())==0)
171 pSrc=GetNextSource();
178 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() const
180 // get first source in the list
181 // TODO: iterator class
182 AliHLTConfiguration* pSrc=NULL;
184 const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx=-1;
185 pSrc=GetNextSource();
190 AliHLTConfiguration* AliHLTConfiguration::GetNextSource() const
193 AliHLTConfiguration* pSrc=NULL;
195 if (fListSrcElementIdx+1<(int)fListSources.size()) {
196 const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx++;
197 pSrc=fListSources[fListSrcElementIdx];
203 int AliHLTConfiguration::SourcesResolved() const
205 // check if all sources are resolved
207 if (fNofSources>=0) {
208 iResult=fNofSources==(int)fListSources.size();
213 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
215 // invalidate state of all sources
218 vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
219 while (element!=fListSources.end()) {
220 if (*element==pConf) {
221 fListSources.erase(element);
222 fListSrcElementIdx=fListSources.size();
223 // there is no need to re-evaluate until there was a new configuration registered
224 // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
225 //InvalidateSources();
236 void AliHLTConfiguration::PrintStatus() const
239 HLTLogKeyword("configuration status");
240 HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
241 if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data());
242 else HLTMessage(" - component string invalid");
243 if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data());
244 else HLTMessage(" - no sources");
245 if (SourcesResolved()!=1)
246 HLTMessage(" there are unresolved sources");
247 AliHLTConfiguration* pSrc=GetFirstSource();
249 HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
250 pSrc=GetNextSource();
254 void AliHLTConfiguration::Print(const char* option) const
257 if (option && strcmp(option, "status")==0) {
261 HLTLogKeyword("configuration");
262 HLTMessage("configuration %s: component %s, sources %s, arguments %s",
266 GetArgumentSettings()
270 int AliHLTConfiguration::GetArguments(const char*** pArgv) const
272 // get argument array
276 if ((iResult=const_cast<AliHLTConfiguration*>(this)->ExtractArguments())<0) {
277 HLTError("error extracting arguments for configuration %s", GetName());
279 } else if (fArgc<0) {
280 HLTError("previous argument extraction failed");
282 //HLTDebug("%s fArgc %d", GetName(), fArgc);
284 *pArgv=(const char**)fArgv;
286 HLTError("invalid parameter");
293 int AliHLTConfiguration::ExtractSources(AliHLTConfigurationHandler* pHandler)
295 // extract source configurations from the handler
296 // TODO: would be less confusing to use 'parent' instead of 'source'
297 // but this needs to be changed consistently throughout the class
299 fNofSources=0; // indicates that the function was called, there are either n or 0 sources
300 fListSources.clear();
302 HLTError("configuration handler missing, can not resolve sources");
305 if (!fStringSources.IsNull()) {
306 vector<char*> tgtList;
307 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
308 fNofSources=tgtList.size();
309 vector<char*>::iterator element=tgtList.begin();
310 while ((element=tgtList.begin())!=tgtList.end()) {
311 AliHLTConfiguration* pConf=pHandler->FindConfiguration(*element);
313 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
314 fListSources.push_back(pConf);
316 HLTError("can not find source \"%s\"", (*element));
320 tgtList.erase(element);
324 fListSrcElementIdx=-1;
325 return iResult<0?iResult:SourcesResolved();
328 int AliHLTConfiguration::ExtractArguments()
330 // extract argument list from string
332 if (!fArguments.IsNull()) {
333 vector<char*> tgtList;
334 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
335 fArgc=tgtList.size();
336 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
338 fArgv = new char*[fArgc];
340 vector<char*>::iterator element=tgtList.begin();
342 while (element!=tgtList.end()) {
343 //HLTDebug("assign arguments %d (%s)", i, *element);
344 fArgv[i++]=(*element);
353 // there are zero arguments
356 if (iResult<0) fArgc=iResult;
360 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
362 // interprete a string
365 //HLTDebug("interprete \"%s\"", arg);
370 //HLTDebug("%d %x", i, arg[i]);
371 if (arg[i]=='\'' && bQuote==0) {
373 } else if (arg[i]==0 ||
374 (arg[i]==' ' && bQuote==0) ||
375 (arg[i]=='\'' && bQuote==1)) {
378 char* pEntry= new char[i-prec+1];
380 strncpy(pEntry, &arg[prec], i-prec);
381 pEntry[i-prec]=0; // terminate string
382 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
383 argList.push_back(pEntry);
388 } else if (prec==-1) prec=i;
389 } while (arg[i++]!=0 && iResult>=0);
396 int AliHLTConfiguration::ConvertSizeString(const char* strSize) const
398 // convert a size argument
400 if (!strSize) return -1;
403 size=strtol(strSize, &endptr, 10);
406 if (endptr==strSize) {
407 HLTWarning("ignoring unrecognized buffer size '%s'", strSize);
409 } else if (*endptr==0) {
411 } else if (*endptr=='k') {
413 } else if (*endptr=='M') {
416 HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]);
419 HLTWarning("ignoring negative buffer size specifier '%s'", strSize);
426 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
428 // follow dependencies
431 AliHLTConfiguration* pDep=NULL;
432 if ((pDep=GetSource(id))!=NULL) {
433 if (pTgtList) pTgtList->Add(pDep);
436 pDep=GetFirstSource();
437 while (pDep && iResult==0) {
438 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
439 if (pTgtList) pTgtList->AddFirst(pDep);
442 pDep=GetNextSource();