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
30 #include "AliHLTConfiguration.h"
31 #include "AliHLTConfigurationHandler.h"
32 #include "AliHLTTask.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTComponentHandler.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTConfiguration)
42 AliHLTConfiguration::AliHLTConfiguration()
49 fListSrcElementIdx(-1),
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources,
63 const char* arguments, const char* bufsize)
66 fComponent(component),
67 fStringSources(sources),
70 fListSrcElementIdx(-1),
71 fArguments(arguments),
76 // see header file for function documentation
77 if (bufsize) fBufferSize=ConvertSizeString(bufsize);
78 if (id && component) {
79 if (AliHLTConfigurationHandler::Instance()) {
80 AliHLTConfigurationHandler::Instance()->RegisterConfiguration(this);
82 AliHLTConfigurationHandler::MissedRegistration(id);
87 AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src)
92 fComponent(src.fComponent),
93 fStringSources(src.fStringSources),
96 fListSrcElementIdx(-1),
97 fArguments(src.fArguments),
100 fBufferSize(src.fBufferSize)
102 // see header file for function documentation
105 AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src)
107 // see header file for function documentation
108 if (this==&src) return *this;
111 fComponent=src.fComponent;
112 fStringSources=src.fStringSources;
114 fArguments=src.fArguments;
117 fBufferSize=src.fBufferSize;
121 AliHLTConfiguration::~AliHLTConfiguration()
123 // see header file for function documentation
124 if (AliHLTConfigurationHandler::Instance()) {
125 if (AliHLTConfigurationHandler::Instance()->FindConfiguration(fID.Data())!=NULL) {
126 // remove the configuration from the handler if it exists
127 // but DO NOT remove the clone configuration
128 AliHLTConfigurationHandler::Instance()->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 const char* AliHLTConfiguration::GetName() const
150 // see header file for function documentation
153 return TObject::GetName();
156 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
158 // see header file for function documentation
159 AliHLTConfiguration* pSrc=NULL;
161 // first check the current element
162 if (fListSrcElementIdx>=0 && fListSrcElementIdx<(int)fListSources.size() &&
163 strcmp(id, (fListSources[fListSrcElementIdx])->GetName())==0) {
164 pSrc=fListSources[fListSrcElementIdx];
168 pSrc=GetFirstSource();
170 if (strcmp(id, pSrc->GetName())==0)
172 pSrc=GetNextSource();
179 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() const
181 // see header file for function documentation
182 AliHLTConfiguration* pSrc=NULL;
184 const_cast<AliHLTConfiguration*>(this)->fListSrcElementIdx=-1;
185 pSrc=GetNextSource();
190 AliHLTConfiguration* AliHLTConfiguration::GetNextSource() const
192 // see header file for function documentation
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 // see header file for function documentation
207 if (fNofSources>=0) {
208 iResult=fNofSources==(int)fListSources.size();
213 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
215 // see header file for function documentation
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
238 // see header file for function documentation
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 // see header file for function documentation
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()
295 // see header file for function documentation
297 fNofSources=0; // indicates that the function was called, there are either n or 0 sources
298 fListSources.clear();
299 AliHLTConfigurationHandler* pHandler=AliHLTConfigurationHandler::Instance();
301 HLTError("global configuration handler not initialized, can not resolve sources");
304 if (!fStringSources.IsNull()) {
305 vector<char*> tgtList;
306 if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) {
307 fNofSources=tgtList.size();
308 vector<char*>::iterator element=tgtList.begin();
309 while ((element=tgtList.begin())!=tgtList.end()) {
310 AliHLTConfiguration* pConf=pHandler->FindConfiguration(*element);
312 //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
313 fListSources.push_back(pConf);
315 HLTError("can not find source \"%s\"", (*element));
319 tgtList.erase(element);
323 fListSrcElementIdx=-1;
324 return iResult<0?iResult:SourcesResolved();
327 int AliHLTConfiguration::ExtractArguments()
329 // see header file for function documentation
331 if (!fArguments.IsNull()) {
332 vector<char*> tgtList;
333 if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
334 fArgc=tgtList.size();
335 //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments);
337 fArgv = new char*[fArgc];
339 vector<char*>::iterator element=tgtList.begin();
341 while (element!=tgtList.end()) {
342 //HLTDebug("assign arguments %d (%s)", i, *element);
343 fArgv[i++]=(*element);
352 // there are zero arguments
355 if (iResult<0) fArgc=iResult;
359 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
361 // see header file for function documentation
364 //HLTDebug("interprete \"%s\"", arg);
369 //HLTDebug("%d %x", i, arg[i]);
370 if (arg[i]=='\'' && bQuote==0) {
372 } else if (arg[i]==0 ||
373 (arg[i]==' ' && bQuote==0) ||
374 (arg[i]=='\'' && bQuote==1)) {
377 char* pEntry= new char[i-prec+1];
379 strncpy(pEntry, &arg[prec], i-prec);
380 pEntry[i-prec]=0; // terminate string
381 //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
382 argList.push_back(pEntry);
387 } else if (prec==-1) prec=i;
388 } while (arg[i++]!=0 && iResult>=0);
395 int AliHLTConfiguration::ConvertSizeString(const char* strSize) const
397 // see header file for function documentation
399 if (!strSize) return -1;
402 size=strtol(strSize, &endptr, 10);
405 if (endptr==strSize) {
406 HLTWarning("ignoring unrecognized buffer size '%s'", strSize);
408 } else if (*endptr==0) {
410 } else if (*endptr=='k') {
412 } else if (*endptr=='M') {
415 HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]);
418 HLTWarning("ignoring negative buffer size specifier '%s'", strSize);
425 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
427 // see header file for function documentation
430 AliHLTConfiguration* pDep=NULL;
431 if ((pDep=GetSource(id))!=NULL) {
432 if (pTgtList) pTgtList->Add(pDep);
435 pDep=GetFirstSource();
436 while (pDep && iResult==0) {
437 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
438 if (pTgtList) pTgtList->AddFirst(pDep);
441 pDep=GetNextSource();