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