]>
Commit | Line | Data |
---|---|---|
3495cce2 | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
3495cce2 | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * | |
3495cce2 | 9 | * * |
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 | **************************************************************************/ | |
18 | ||
b22e91eb | 19 | /** @file AliHLTConfiguration.cxx |
20 | @author Matthias Richter | |
21 | @date | |
7a436c89 | 22 | @brief Implementation of HLT configurations. |
b22e91eb | 23 | */ |
3495cce2 | 24 | |
3a7c0444 | 25 | // see header file for class documentation |
26 | // or | |
27 | // refer to README to build package | |
28 | // or | |
29 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
30 | ||
0c0c9d99 | 31 | #if __GNUC__>= 3 |
3495cce2 | 32 | using namespace std; |
33 | #endif | |
34 | ||
a5854ddd | 35 | #include <cerrno> |
3495cce2 | 36 | #include "AliHLTConfiguration.h" |
c38ba6f9 | 37 | #include "AliHLTConfigurationHandler.h" |
38 | #include "AliHLTTask.h" | |
3495cce2 | 39 | #include "AliHLTComponent.h" |
40 | #include "AliHLTComponentHandler.h" | |
41 | #include <iostream> | |
a5854ddd | 42 | #include <string> |
70ed7d01 | 43 | #include "TList.h" |
3495cce2 | 44 | |
b22e91eb | 45 | /** ROOT macro for the implementation of ROOT specific class methods */ |
3495cce2 | 46 | ClassImp(AliHLTConfiguration) |
47 | ||
48 | AliHLTConfiguration::AliHLTConfiguration() | |
85869391 | 49 | : |
52c1c164 | 50 | fID(""), |
51 | fComponent(""), | |
52 | fStringSources(""), | |
85869391 | 53 | fNofSources(-1), |
53feaef5 | 54 | fListSources(), |
55 | fListSrcElement(), | |
52c1c164 | 56 | fArguments(""), |
85869391 | 57 | fArgc(-1), |
032c5e5e | 58 | fArgv(NULL), |
59 | fBufferSize(-1) | |
3495cce2 | 60 | { |
3a7c0444 | 61 | // see header file for class documentation |
62 | // or | |
63 | // refer to README to build package | |
64 | // or | |
65 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
66 | ||
3495cce2 | 67 | fListSrcElement=fListSources.begin(); |
68 | } | |
69 | ||
032c5e5e | 70 | AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, |
71 | const char* arguments, const char* bufsize) | |
85869391 | 72 | : |
73 | fID(id), | |
74 | fComponent(component), | |
75 | fStringSources(sources), | |
76 | fNofSources(-1), | |
53feaef5 | 77 | fListSources(), |
78 | fListSrcElement(), | |
85869391 | 79 | fArguments(arguments), |
80 | fArgc(-1), | |
032c5e5e | 81 | fArgv(NULL), |
82 | fBufferSize(-1) | |
3495cce2 | 83 | { |
70ed7d01 | 84 | // see header file for function documentation |
032c5e5e | 85 | if (bufsize) fBufferSize=ConvertSizeString(bufsize); |
85869391 | 86 | fListSrcElement=fListSources.begin(); |
3495cce2 | 87 | if (id && component) { |
70ed7d01 | 88 | if (fgConfigurationHandler) { |
89 | fgConfigurationHandler->RegisterConfiguration(this); | |
85465857 | 90 | } else { |
91 | HLTError("no configuration handler set, abort registration"); | |
92 | } | |
3495cce2 | 93 | } |
94 | } | |
95 | ||
fc455fba | 96 | AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src) |
85869391 | 97 | : |
53feaef5 | 98 | TObject(), |
99 | AliHLTLogging(), | |
fc455fba | 100 | fID(src.fID), |
101 | fComponent(src.fComponent), | |
102 | fStringSources(src.fStringSources), | |
85869391 | 103 | fNofSources(-1), |
53feaef5 | 104 | fListSources(), |
105 | fListSrcElement(), | |
fc455fba | 106 | fArguments(src.fArguments), |
85869391 | 107 | fArgc(-1), |
032c5e5e | 108 | fArgv(NULL), |
109 | fBufferSize(src.fBufferSize) | |
85869391 | 110 | { |
70ed7d01 | 111 | // see header file for function documentation |
85869391 | 112 | fListSrcElement=fListSources.begin(); |
85869391 | 113 | } |
114 | ||
fc455fba | 115 | AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src) |
85869391 | 116 | { |
70ed7d01 | 117 | // see header file for function documentation |
fc455fba | 118 | fID=src.fID; |
119 | fComponent=src.fComponent; | |
120 | fStringSources=src.fStringSources; | |
121 | fNofSources=-1; | |
122 | fArguments=src.fArguments; | |
123 | fArgc=-1; | |
124 | fArgv=NULL; | |
032c5e5e | 125 | fBufferSize=src.fBufferSize; |
85869391 | 126 | return *this; |
127 | } | |
128 | ||
3495cce2 | 129 | AliHLTConfiguration::~AliHLTConfiguration() |
130 | { | |
70ed7d01 | 131 | // see header file for function documentation |
132 | if (fgConfigurationHandler) { | |
52c1c164 | 133 | if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) { |
325e5e42 | 134 | // 30 Dec 2009 - Cannot use the 'this' pointer in the RemoveConfiguration |
135 | // method since the fgConfigurationHandler contains clone objects and therefor | |
136 | // the remove method will not find this object in the list to remove. | |
137 | //fgConfigurationHandler->RemoveConfiguration(this); | |
138 | fgConfigurationHandler->RemoveConfiguration(fID.Data()); | |
85465857 | 139 | } |
3495cce2 | 140 | } |
141 | if (fArgv != NULL) { | |
142 | if (fArgc>0) { | |
143 | for (int i=0; i<fArgc; i++) { | |
144 | delete[] fArgv[i]; | |
145 | } | |
146 | } | |
147 | delete[] fArgv; | |
148 | fArgv=NULL; | |
149 | } | |
a742f6f8 | 150 | |
151 | vector<AliHLTConfiguration*>::iterator element=fListSources.begin(); | |
152 | while (element!=fListSources.end()) { | |
153 | fListSources.erase(element); | |
154 | element=fListSources.begin(); | |
155 | } | |
3495cce2 | 156 | } |
157 | ||
b22e91eb | 158 | /* the global configuration handler which is used to automatically register the configuration |
159 | */ | |
70ed7d01 | 160 | AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL; |
b22e91eb | 161 | |
85465857 | 162 | int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler) |
163 | { | |
70ed7d01 | 164 | // see header file for function documentation |
85465857 | 165 | int iResult=0; |
95654878 | 166 | if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) { |
fc455fba | 167 | fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler); |
85465857 | 168 | } |
70ed7d01 | 169 | fgConfigurationHandler=pHandler; |
85465857 | 170 | return iResult; |
171 | } | |
172 | ||
fc455fba | 173 | int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler) |
85465857 | 174 | { |
70ed7d01 | 175 | // see header file for function documentation |
85465857 | 176 | int iResult=0; |
20101b23 | 177 | if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) { |
fc455fba | 178 | fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler); |
179 | return -EBADF; | |
180 | } | |
70ed7d01 | 181 | fgConfigurationHandler=NULL; |
85465857 | 182 | return iResult; |
183 | } | |
184 | ||
70ed7d01 | 185 | const char* AliHLTConfiguration::GetName() const |
186 | { | |
187 | // see header file for function documentation | |
52c1c164 | 188 | if (!fID.IsNull()) |
189 | return fID.Data(); | |
3495cce2 | 190 | return TObject::GetName(); |
191 | } | |
192 | ||
193 | AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id) | |
194 | { | |
70ed7d01 | 195 | // see header file for function documentation |
3495cce2 | 196 | AliHLTConfiguration* pSrc=NULL; |
197 | if (id) { | |
198 | // first check the current element | |
199 | if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) { | |
200 | pSrc=*fListSrcElement; | |
201 | } else { | |
202 | // check the list | |
203 | ||
204 | pSrc=GetFirstSource(); | |
205 | while (pSrc) { | |
206 | if (strcmp(id, pSrc->GetName())==0) | |
207 | break; | |
208 | pSrc=GetNextSource(); | |
209 | } | |
210 | } | |
211 | } | |
212 | return pSrc; | |
213 | } | |
214 | ||
215 | AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() | |
216 | { | |
70ed7d01 | 217 | // see header file for function documentation |
3495cce2 | 218 | AliHLTConfiguration* pSrc=NULL; |
95654878 | 219 | if (fNofSources>=0 || ExtractSources()>=0) { |
3495cce2 | 220 | fListSrcElement=fListSources.begin(); |
221 | if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement; | |
222 | } | |
223 | return pSrc; | |
224 | } | |
225 | ||
226 | AliHLTConfiguration* AliHLTConfiguration::GetNextSource() | |
227 | { | |
70ed7d01 | 228 | // see header file for function documentation |
3495cce2 | 229 | AliHLTConfiguration* pSrc=NULL; |
230 | if (fNofSources>0) { | |
231 | if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) | |
232 | pSrc=*fListSrcElement; | |
233 | } | |
234 | return pSrc; | |
235 | } | |
236 | ||
237 | int AliHLTConfiguration::SourcesResolved(int bAuto) | |
238 | { | |
70ed7d01 | 239 | // see header file for function documentation |
3495cce2 | 240 | int iResult=0; |
95e36f3d | 241 | if (fNofSources>=0 || (bAuto && (iResult=ExtractSources()))>=0) { |
85465857 | 242 | //HLTDebug("fNofSources=%d", fNofSources); |
243 | //HLTDebug("list size = %d", fListSources.size()); | |
3495cce2 | 244 | iResult=fNofSources==(int)fListSources.size(); |
245 | } | |
246 | return iResult; | |
247 | } | |
248 | ||
249 | int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf) | |
250 | { | |
70ed7d01 | 251 | // see header file for function documentation |
3495cce2 | 252 | int iResult=0; |
253 | if (pConf) { | |
254 | vector<AliHLTConfiguration*>::iterator element=fListSources.begin(); | |
255 | while (element!=fListSources.end()) { | |
256 | if (*element==pConf) { | |
257 | fListSources.erase(element); | |
258 | fListSrcElement=fListSources.end(); | |
259 | // there is no need to re-evaluate until there was a new configuration registered | |
260 | // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration | |
261 | //InvalidateSources(); | |
262 | break; | |
263 | } | |
264 | element++; | |
265 | } | |
266 | } else { | |
267 | iResult=-EINVAL; | |
268 | } | |
269 | return iResult; | |
270 | } | |
271 | ||
272 | void AliHLTConfiguration::PrintStatus() | |
273 | { | |
70ed7d01 | 274 | // see header file for function documentation |
85465857 | 275 | HLTLogKeyword("configuration status"); |
276 | HLTMessage("status of configuration \"%s\" (%p)", GetName(), this); | |
52c1c164 | 277 | if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data()); |
85465857 | 278 | else HLTMessage(" - component string invalid"); |
52c1c164 | 279 | if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data()); |
85465857 | 280 | else HLTMessage(" - no sources"); |
3495cce2 | 281 | if (SourcesResolved(1)<=0) |
85465857 | 282 | HLTMessage(" there are unresolved sources"); |
3495cce2 | 283 | AliHLTConfiguration* pSrc=GetFirstSource(); |
284 | while (pSrc) { | |
85465857 | 285 | HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc); |
3495cce2 | 286 | pSrc=GetNextSource(); |
287 | } | |
288 | } | |
289 | ||
0c0c9d99 | 290 | int AliHLTConfiguration::GetArguments(const char*** pArgv) |
3495cce2 | 291 | { |
70ed7d01 | 292 | // see header file for function documentation |
3495cce2 | 293 | int iResult=0; |
0c0c9d99 | 294 | if (pArgv) { |
9ce4bf4a | 295 | if (fArgc==-1) { |
296 | if ((iResult=ExtractArguments())<0) { | |
297 | HLTError("error extracting arguments for configuration %s", GetName()); | |
298 | fArgc=-EINVAL; | |
299 | } | |
300 | } else if (fArgc<0) { | |
301 | HLTError("previous argument extraction failed"); | |
302 | } | |
303 | //HLTDebug("%s fArgc %d", GetName(), fArgc); | |
0c0c9d99 | 304 | iResult=fArgc; |
3495cce2 | 305 | *pArgv=(const char**)fArgv; |
306 | } else { | |
9ce4bf4a | 307 | HLTError("invalid parameter"); |
3495cce2 | 308 | iResult=-EINVAL; |
309 | } | |
310 | return iResult; | |
311 | } | |
312 | ||
313 | ||
314 | int AliHLTConfiguration::ExtractSources() | |
315 | { | |
70ed7d01 | 316 | // see header file for function documentation |
3495cce2 | 317 | int iResult=0; |
318 | fNofSources=0; | |
52c1c164 | 319 | if (!fStringSources.IsNull()) { |
3495cce2 | 320 | vector<char*> tgtList; |
321 | fListSources.clear(); | |
52c1c164 | 322 | if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) { |
3495cce2 | 323 | fNofSources=tgtList.size(); |
324 | vector<char*>::iterator element=tgtList.begin(); | |
85465857 | 325 | while ((element=tgtList.begin())!=tgtList.end()) { |
70ed7d01 | 326 | if (fgConfigurationHandler) { |
327 | AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element); | |
85465857 | 328 | if (pConf) { |
a742f6f8 | 329 | //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf); |
85465857 | 330 | fListSources.push_back(pConf); |
331 | } else { | |
332 | HLTError("can not find source \"%s\"", (*element)); | |
333 | iResult=-ENOENT; | |
334 | } | |
335 | } else if (iResult>=0) { | |
336 | iResult=-EFAULT; | |
337 | HLTFatal("global configuration handler not initialized, can not resolve sources"); | |
3495cce2 | 338 | } |
339 | delete[] (*element); | |
340 | tgtList.erase(element); | |
341 | } | |
342 | fListSrcElement=fListSources.begin(); | |
343 | } | |
344 | } | |
345 | return iResult; | |
346 | } | |
347 | ||
348 | int AliHLTConfiguration::ExtractArguments() | |
349 | { | |
70ed7d01 | 350 | // see header file for function documentation |
3495cce2 | 351 | int iResult=0; |
52c1c164 | 352 | if (!fArguments.IsNull()) { |
3495cce2 | 353 | vector<char*> tgtList; |
354 | if ((iResult=InterpreteString(fArguments, tgtList))>=0) { | |
355 | fArgc=tgtList.size(); | |
9ce4bf4a | 356 | //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments); |
3495cce2 | 357 | if (fArgc>0) { |
358 | fArgv = new char*[fArgc]; | |
359 | if (fArgv) { | |
360 | vector<char*>::iterator element=tgtList.begin(); | |
361 | int i=0; | |
362 | while (element!=tgtList.end()) { | |
85465857 | 363 | //HLTDebug("assign arguments %d (%s)", i, *element); |
3495cce2 | 364 | fArgv[i++]=(*element); |
365 | element++; | |
366 | } | |
367 | } else { | |
368 | iResult=-ENOMEM; | |
369 | } | |
370 | } | |
371 | } | |
9ce4bf4a | 372 | } else { |
373 | // there are zero arguments | |
374 | fArgc=0; | |
3495cce2 | 375 | } |
376 | return iResult; | |
377 | } | |
378 | ||
4b31e06b | 379 | int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList) |
3495cce2 | 380 | { |
70ed7d01 | 381 | // see header file for function documentation |
3495cce2 | 382 | int iResult=0; |
383 | if (arg) { | |
85465857 | 384 | //HLTDebug("interprete \"%s\"", arg); |
3495cce2 | 385 | int i=0; |
386 | int prec=-1; | |
5f5b708b | 387 | int bQuote=0; |
3495cce2 | 388 | do { |
5f5b708b | 389 | //HLTDebug("%d %x", i, arg[i]); |
390 | if (arg[i]=='\'' && bQuote==0) { | |
391 | bQuote=1; | |
392 | } else if (arg[i]==0 || | |
393 | (arg[i]==' ' && bQuote==0) || | |
394 | (arg[i]=='\'' && bQuote==1)) { | |
395 | bQuote=0; | |
3495cce2 | 396 | if (prec>=0) { |
397 | char* pEntry= new char[i-prec+1]; | |
398 | if (pEntry) { | |
399 | strncpy(pEntry, &arg[prec], i-prec); | |
400 | pEntry[i-prec]=0; // terminate string | |
85465857 | 401 | //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size()); |
3495cce2 | 402 | argList.push_back(pEntry); |
403 | } else | |
404 | iResult=-ENOMEM; | |
405 | prec=-1; | |
406 | } | |
407 | } else if (prec==-1) prec=i; | |
408 | } while (arg[i++]!=0 && iResult>=0); | |
409 | } else { | |
410 | iResult=-EINVAL; | |
411 | } | |
412 | return iResult; | |
413 | } | |
414 | ||
032c5e5e | 415 | int AliHLTConfiguration::ConvertSizeString(const char* strSize) const |
416 | { | |
417 | // see header file for function documentation | |
418 | int size=0; | |
419 | if (!strSize) return -1; | |
420 | ||
421 | char* endptr=NULL; | |
422 | size=strtol(strSize, &endptr, 10); | |
423 | if (size>=0) { | |
424 | if (endptr) { | |
425 | if (endptr==strSize) { | |
426 | HLTWarning("ignoring unrecognized buffer size '%s'", strSize); | |
427 | size=-1; | |
428 | } else if (*endptr==0) { | |
429 | // no unit specifier | |
430 | } else if (*endptr=='k') { | |
431 | size*=1014; | |
432 | } else if (*endptr=='M') { | |
433 | size*=1024*1024; | |
434 | } else { | |
435 | HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]); | |
436 | } | |
437 | } else { | |
438 | HLTWarning("ignoring negative buffer size specifier '%s'", strSize); | |
439 | size=-1; | |
440 | } | |
441 | } | |
442 | return size; | |
443 | } | |
444 | ||
3495cce2 | 445 | int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList) |
446 | { | |
70ed7d01 | 447 | // see header file for function documentation |
3495cce2 | 448 | int iResult=0; |
449 | if (id) { | |
450 | AliHLTConfiguration* pDep=NULL; | |
451 | if ((pDep=GetSource(id))!=NULL) { | |
452 | if (pTgtList) pTgtList->Add(pDep); | |
453 | iResult++; | |
454 | } else { | |
455 | pDep=GetFirstSource(); | |
456 | while (pDep && iResult==0) { | |
457 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
458 | if (pTgtList) pTgtList->AddFirst(pDep); | |
459 | iResult++; | |
460 | } | |
461 | pDep=GetNextSource(); | |
462 | } | |
463 | } | |
464 | } else { | |
465 | iResult=-EINVAL; | |
466 | } | |
467 | return iResult; | |
468 | } | |
469 | ||
3495cce2 | 470 |