]>
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), |
53feaef5 | 58 | fArgv(NULL) |
3495cce2 | 59 | { |
3a7c0444 | 60 | // see header file for class documentation |
61 | // or | |
62 | // refer to README to build package | |
63 | // or | |
64 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
65 | ||
3495cce2 | 66 | fListSrcElement=fListSources.begin(); |
67 | } | |
68 | ||
69 | AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments) | |
85869391 | 70 | : |
71 | fID(id), | |
72 | fComponent(component), | |
73 | fStringSources(sources), | |
74 | fNofSources(-1), | |
53feaef5 | 75 | fListSources(), |
76 | fListSrcElement(), | |
85869391 | 77 | fArguments(arguments), |
78 | fArgc(-1), | |
53feaef5 | 79 | fArgv(NULL) |
3495cce2 | 80 | { |
70ed7d01 | 81 | // see header file for function documentation |
85869391 | 82 | fListSrcElement=fListSources.begin(); |
3495cce2 | 83 | if (id && component) { |
70ed7d01 | 84 | if (fgConfigurationHandler) { |
85 | fgConfigurationHandler->RegisterConfiguration(this); | |
85465857 | 86 | } else { |
87 | HLTError("no configuration handler set, abort registration"); | |
88 | } | |
3495cce2 | 89 | } |
90 | } | |
91 | ||
fc455fba | 92 | AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src) |
85869391 | 93 | : |
53feaef5 | 94 | TObject(), |
95 | AliHLTLogging(), | |
fc455fba | 96 | fID(src.fID), |
97 | fComponent(src.fComponent), | |
98 | fStringSources(src.fStringSources), | |
85869391 | 99 | fNofSources(-1), |
53feaef5 | 100 | fListSources(), |
101 | fListSrcElement(), | |
fc455fba | 102 | fArguments(src.fArguments), |
85869391 | 103 | fArgc(-1), |
53feaef5 | 104 | fArgv(NULL) |
85869391 | 105 | { |
70ed7d01 | 106 | // see header file for function documentation |
85869391 | 107 | fListSrcElement=fListSources.begin(); |
85869391 | 108 | } |
109 | ||
fc455fba | 110 | AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src) |
85869391 | 111 | { |
70ed7d01 | 112 | // see header file for function documentation |
fc455fba | 113 | fID=src.fID; |
114 | fComponent=src.fComponent; | |
115 | fStringSources=src.fStringSources; | |
116 | fNofSources=-1; | |
117 | fArguments=src.fArguments; | |
118 | fArgc=-1; | |
119 | fArgv=NULL; | |
85869391 | 120 | return *this; |
121 | } | |
122 | ||
3495cce2 | 123 | AliHLTConfiguration::~AliHLTConfiguration() |
124 | { | |
70ed7d01 | 125 | // see header file for function documentation |
126 | if (fgConfigurationHandler) { | |
52c1c164 | 127 | if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) { |
70ed7d01 | 128 | fgConfigurationHandler->RemoveConfiguration(this); |
85465857 | 129 | } |
3495cce2 | 130 | } |
131 | if (fArgv != NULL) { | |
132 | if (fArgc>0) { | |
133 | for (int i=0; i<fArgc; i++) { | |
134 | delete[] fArgv[i]; | |
135 | } | |
136 | } | |
137 | delete[] fArgv; | |
138 | fArgv=NULL; | |
139 | } | |
a742f6f8 | 140 | |
141 | vector<AliHLTConfiguration*>::iterator element=fListSources.begin(); | |
142 | while (element!=fListSources.end()) { | |
143 | fListSources.erase(element); | |
144 | element=fListSources.begin(); | |
145 | } | |
3495cce2 | 146 | } |
147 | ||
b22e91eb | 148 | /* the global configuration handler which is used to automatically register the configuration |
149 | */ | |
70ed7d01 | 150 | AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL; |
b22e91eb | 151 | |
85465857 | 152 | int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler) |
153 | { | |
70ed7d01 | 154 | // see header file for function documentation |
85465857 | 155 | int iResult=0; |
70ed7d01 | 156 | if (fgConfigurationHandler!=NULL) { |
fc455fba | 157 | fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler); |
85465857 | 158 | } |
70ed7d01 | 159 | fgConfigurationHandler=pHandler; |
85465857 | 160 | return iResult; |
161 | } | |
162 | ||
fc455fba | 163 | int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler) |
85465857 | 164 | { |
70ed7d01 | 165 | // see header file for function documentation |
85465857 | 166 | int iResult=0; |
fc455fba | 167 | if (pHandler!=NULL && fgConfigurationHandler!=pHandler) { |
168 | fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler); | |
169 | return -EBADF; | |
170 | } | |
70ed7d01 | 171 | fgConfigurationHandler=NULL; |
85465857 | 172 | return iResult; |
173 | } | |
174 | ||
70ed7d01 | 175 | const char* AliHLTConfiguration::GetName() const |
176 | { | |
177 | // see header file for function documentation | |
52c1c164 | 178 | if (!fID.IsNull()) |
179 | return fID.Data(); | |
3495cce2 | 180 | return TObject::GetName(); |
181 | } | |
182 | ||
183 | AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id) | |
184 | { | |
70ed7d01 | 185 | // see header file for function documentation |
3495cce2 | 186 | AliHLTConfiguration* pSrc=NULL; |
187 | if (id) { | |
188 | // first check the current element | |
189 | if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) { | |
190 | pSrc=*fListSrcElement; | |
191 | } else { | |
192 | // check the list | |
193 | ||
194 | pSrc=GetFirstSource(); | |
195 | while (pSrc) { | |
196 | if (strcmp(id, pSrc->GetName())==0) | |
197 | break; | |
198 | pSrc=GetNextSource(); | |
199 | } | |
200 | } | |
201 | } | |
202 | return pSrc; | |
203 | } | |
204 | ||
205 | AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() | |
206 | { | |
70ed7d01 | 207 | // see header file for function documentation |
3495cce2 | 208 | AliHLTConfiguration* pSrc=NULL; |
209 | if (fNofSources>=0 || ExtractSources()) { | |
210 | fListSrcElement=fListSources.begin(); | |
211 | if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement; | |
212 | } | |
213 | return pSrc; | |
214 | } | |
215 | ||
216 | AliHLTConfiguration* AliHLTConfiguration::GetNextSource() | |
217 | { | |
70ed7d01 | 218 | // see header file for function documentation |
3495cce2 | 219 | AliHLTConfiguration* pSrc=NULL; |
220 | if (fNofSources>0) { | |
221 | if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) | |
222 | pSrc=*fListSrcElement; | |
223 | } | |
224 | return pSrc; | |
225 | } | |
226 | ||
227 | int AliHLTConfiguration::SourcesResolved(int bAuto) | |
228 | { | |
70ed7d01 | 229 | // see header file for function documentation |
3495cce2 | 230 | int iResult=0; |
231 | if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) { | |
85465857 | 232 | //HLTDebug("fNofSources=%d", fNofSources); |
233 | //HLTDebug("list size = %d", fListSources.size()); | |
3495cce2 | 234 | iResult=fNofSources==(int)fListSources.size(); |
235 | } | |
236 | return iResult; | |
237 | } | |
238 | ||
239 | int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf) | |
240 | { | |
70ed7d01 | 241 | // see header file for function documentation |
3495cce2 | 242 | int iResult=0; |
243 | if (pConf) { | |
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(); | |
252 | break; | |
253 | } | |
254 | element++; | |
255 | } | |
256 | } else { | |
257 | iResult=-EINVAL; | |
258 | } | |
259 | return iResult; | |
260 | } | |
261 | ||
262 | void AliHLTConfiguration::PrintStatus() | |
263 | { | |
70ed7d01 | 264 | // see header file for function documentation |
85465857 | 265 | HLTLogKeyword("configuration status"); |
266 | HLTMessage("status of configuration \"%s\" (%p)", GetName(), this); | |
52c1c164 | 267 | if (!fComponent.IsNull()) HLTMessage(" - component: \"%s\"", fComponent.Data()); |
85465857 | 268 | else HLTMessage(" - component string invalid"); |
52c1c164 | 269 | if (!fStringSources.IsNull()) HLTMessage(" - sources: \"%s\"", fStringSources.Data()); |
85465857 | 270 | else HLTMessage(" - no sources"); |
3495cce2 | 271 | if (SourcesResolved(1)<=0) |
85465857 | 272 | HLTMessage(" there are unresolved sources"); |
3495cce2 | 273 | AliHLTConfiguration* pSrc=GetFirstSource(); |
274 | while (pSrc) { | |
85465857 | 275 | HLTMessage(" source \"%s\" (%p) resolved", pSrc->GetName(), pSrc); |
3495cce2 | 276 | pSrc=GetNextSource(); |
277 | } | |
278 | } | |
279 | ||
0c0c9d99 | 280 | int AliHLTConfiguration::GetArguments(const char*** pArgv) |
3495cce2 | 281 | { |
70ed7d01 | 282 | // see header file for function documentation |
3495cce2 | 283 | int iResult=0; |
0c0c9d99 | 284 | if (pArgv) { |
9ce4bf4a | 285 | if (fArgc==-1) { |
286 | if ((iResult=ExtractArguments())<0) { | |
287 | HLTError("error extracting arguments for configuration %s", GetName()); | |
288 | fArgc=-EINVAL; | |
289 | } | |
290 | } else if (fArgc<0) { | |
291 | HLTError("previous argument extraction failed"); | |
292 | } | |
293 | //HLTDebug("%s fArgc %d", GetName(), fArgc); | |
0c0c9d99 | 294 | iResult=fArgc; |
3495cce2 | 295 | *pArgv=(const char**)fArgv; |
296 | } else { | |
9ce4bf4a | 297 | HLTError("invalid parameter"); |
3495cce2 | 298 | iResult=-EINVAL; |
299 | } | |
300 | return iResult; | |
301 | } | |
302 | ||
303 | ||
304 | int AliHLTConfiguration::ExtractSources() | |
305 | { | |
70ed7d01 | 306 | // see header file for function documentation |
3495cce2 | 307 | int iResult=0; |
308 | fNofSources=0; | |
52c1c164 | 309 | if (!fStringSources.IsNull()) { |
3495cce2 | 310 | vector<char*> tgtList; |
311 | fListSources.clear(); | |
52c1c164 | 312 | if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) { |
3495cce2 | 313 | fNofSources=tgtList.size(); |
314 | vector<char*>::iterator element=tgtList.begin(); | |
85465857 | 315 | while ((element=tgtList.begin())!=tgtList.end()) { |
70ed7d01 | 316 | if (fgConfigurationHandler) { |
317 | AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element); | |
85465857 | 318 | if (pConf) { |
a742f6f8 | 319 | //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf); |
85465857 | 320 | fListSources.push_back(pConf); |
321 | } else { | |
322 | HLTError("can not find source \"%s\"", (*element)); | |
323 | iResult=-ENOENT; | |
324 | } | |
325 | } else if (iResult>=0) { | |
326 | iResult=-EFAULT; | |
327 | HLTFatal("global configuration handler not initialized, can not resolve sources"); | |
3495cce2 | 328 | } |
329 | delete[] (*element); | |
330 | tgtList.erase(element); | |
331 | } | |
332 | fListSrcElement=fListSources.begin(); | |
333 | } | |
334 | } | |
335 | return iResult; | |
336 | } | |
337 | ||
338 | int AliHLTConfiguration::ExtractArguments() | |
339 | { | |
70ed7d01 | 340 | // see header file for function documentation |
3495cce2 | 341 | int iResult=0; |
52c1c164 | 342 | if (!fArguments.IsNull()) { |
3495cce2 | 343 | vector<char*> tgtList; |
344 | if ((iResult=InterpreteString(fArguments, tgtList))>=0) { | |
345 | fArgc=tgtList.size(); | |
9ce4bf4a | 346 | //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments); |
3495cce2 | 347 | if (fArgc>0) { |
348 | fArgv = new char*[fArgc]; | |
349 | if (fArgv) { | |
350 | vector<char*>::iterator element=tgtList.begin(); | |
351 | int i=0; | |
352 | while (element!=tgtList.end()) { | |
85465857 | 353 | //HLTDebug("assign arguments %d (%s)", i, *element); |
3495cce2 | 354 | fArgv[i++]=(*element); |
355 | element++; | |
356 | } | |
357 | } else { | |
358 | iResult=-ENOMEM; | |
359 | } | |
360 | } | |
361 | } | |
9ce4bf4a | 362 | } else { |
363 | // there are zero arguments | |
364 | fArgc=0; | |
3495cce2 | 365 | } |
366 | return iResult; | |
367 | } | |
368 | ||
369 | int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList) | |
370 | { | |
70ed7d01 | 371 | // see header file for function documentation |
3495cce2 | 372 | int iResult=0; |
373 | if (arg) { | |
85465857 | 374 | //HLTDebug("interprete \"%s\"", arg); |
3495cce2 | 375 | int i=0; |
376 | int prec=-1; | |
5f5b708b | 377 | int bQuote=0; |
3495cce2 | 378 | do { |
5f5b708b | 379 | //HLTDebug("%d %x", i, arg[i]); |
380 | if (arg[i]=='\'' && bQuote==0) { | |
381 | bQuote=1; | |
382 | } else if (arg[i]==0 || | |
383 | (arg[i]==' ' && bQuote==0) || | |
384 | (arg[i]=='\'' && bQuote==1)) { | |
385 | bQuote=0; | |
3495cce2 | 386 | if (prec>=0) { |
387 | char* pEntry= new char[i-prec+1]; | |
388 | if (pEntry) { | |
389 | strncpy(pEntry, &arg[prec], i-prec); | |
390 | pEntry[i-prec]=0; // terminate string | |
85465857 | 391 | //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size()); |
3495cce2 | 392 | argList.push_back(pEntry); |
393 | } else | |
394 | iResult=-ENOMEM; | |
395 | prec=-1; | |
396 | } | |
397 | } else if (prec==-1) prec=i; | |
398 | } while (arg[i++]!=0 && iResult>=0); | |
399 | } else { | |
400 | iResult=-EINVAL; | |
401 | } | |
402 | return iResult; | |
403 | } | |
404 | ||
405 | int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList) | |
406 | { | |
70ed7d01 | 407 | // see header file for function documentation |
3495cce2 | 408 | int iResult=0; |
409 | if (id) { | |
410 | AliHLTConfiguration* pDep=NULL; | |
411 | if ((pDep=GetSource(id))!=NULL) { | |
412 | if (pTgtList) pTgtList->Add(pDep); | |
413 | iResult++; | |
414 | } else { | |
415 | pDep=GetFirstSource(); | |
416 | while (pDep && iResult==0) { | |
417 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
418 | if (pTgtList) pTgtList->AddFirst(pDep); | |
419 | iResult++; | |
420 | } | |
421 | pDep=GetNextSource(); | |
422 | } | |
423 | } | |
424 | } else { | |
425 | iResult=-EINVAL; | |
426 | } | |
427 | return iResult; | |
428 | } | |
429 | ||
3495cce2 | 430 |