]>
Commit | Line | Data |
---|---|---|
3495cce2 | 1 | // $Id$ |
2 | ||
4403fb69 | 3 | ///************************************************************************** |
c515df4c | 4 | ///* This file is property of and copyright by the * |
4403fb69 | 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 | |
a5854ddd | 25 | #include <cerrno> |
3495cce2 | 26 | #include "AliHLTConfiguration.h" |
c38ba6f9 | 27 | #include "AliHLTConfigurationHandler.h" |
28 | #include "AliHLTTask.h" | |
3495cce2 | 29 | #include "AliHLTComponent.h" |
30 | #include "AliHLTComponentHandler.h" | |
31 | #include <iostream> | |
a5854ddd | 32 | #include <string> |
70ed7d01 | 33 | #include "TList.h" |
3495cce2 | 34 | |
c515df4c | 35 | using std::vector; |
36 | ||
b22e91eb | 37 | /** ROOT macro for the implementation of ROOT specific class methods */ |
3495cce2 | 38 | ClassImp(AliHLTConfiguration) |
39 | ||
40 | AliHLTConfiguration::AliHLTConfiguration() | |
85869391 | 41 | : |
52c1c164 | 42 | fID(""), |
43 | fComponent(""), | |
44 | fStringSources(""), | |
85869391 | 45 | fNofSources(-1), |
53feaef5 | 46 | fListSources(), |
d174bfc3 | 47 | fListSrcElementIdx(-1), |
52c1c164 | 48 | fArguments(""), |
85869391 | 49 | fArgc(-1), |
032c5e5e | 50 | fArgv(NULL), |
51 | fBufferSize(-1) | |
3495cce2 | 52 | { |
c515df4c | 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 | |
3495cce2 | 59 | } |
60 | ||
032c5e5e | 61 | AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, |
62 | const char* arguments, const char* bufsize) | |
85869391 | 63 | : |
64 | fID(id), | |
65 | fComponent(component), | |
66 | fStringSources(sources), | |
67 | fNofSources(-1), | |
53feaef5 | 68 | fListSources(), |
d174bfc3 | 69 | fListSrcElementIdx(-1), |
85869391 | 70 | fArguments(arguments), |
71 | fArgc(-1), | |
032c5e5e | 72 | fArgv(NULL), |
73 | fBufferSize(-1) | |
3495cce2 | 74 | { |
c515df4c | 75 | // constructor |
032c5e5e | 76 | if (bufsize) fBufferSize=ConvertSizeString(bufsize); |
3495cce2 | 77 | if (id && component) { |
4403fb69 | 78 | if (AliHLTConfigurationHandler::Instance()) { |
79 | AliHLTConfigurationHandler::Instance()->RegisterConfiguration(this); | |
85465857 | 80 | } else { |
4403fb69 | 81 | AliHLTConfigurationHandler::MissedRegistration(id); |
85465857 | 82 | } |
3495cce2 | 83 | } |
84 | } | |
85 | ||
fc455fba | 86 | AliHLTConfiguration::AliHLTConfiguration(const AliHLTConfiguration& src) |
85869391 | 87 | : |
53feaef5 | 88 | TObject(), |
89 | AliHLTLogging(), | |
fc455fba | 90 | fID(src.fID), |
91 | fComponent(src.fComponent), | |
92 | fStringSources(src.fStringSources), | |
85869391 | 93 | fNofSources(-1), |
53feaef5 | 94 | fListSources(), |
d174bfc3 | 95 | fListSrcElementIdx(-1), |
fc455fba | 96 | fArguments(src.fArguments), |
85869391 | 97 | fArgc(-1), |
032c5e5e | 98 | fArgv(NULL), |
99 | fBufferSize(src.fBufferSize) | |
85869391 | 100 | { |
c515df4c | 101 | // copy constructor |
85869391 | 102 | } |
103 | ||
fc455fba | 104 | AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& src) |
85869391 | 105 | { |
c515df4c | 106 | // assignment operator |
d174bfc3 | 107 | if (this==&src) return *this; |
108 | ||
fc455fba | 109 | fID=src.fID; |
110 | fComponent=src.fComponent; | |
111 | fStringSources=src.fStringSources; | |
112 | fNofSources=-1; | |
113 | fArguments=src.fArguments; | |
114 | fArgc=-1; | |
115 | fArgv=NULL; | |
032c5e5e | 116 | fBufferSize=src.fBufferSize; |
85869391 | 117 | return *this; |
118 | } | |
119 | ||
3495cce2 | 120 | AliHLTConfiguration::~AliHLTConfiguration() |
121 | { | |
c515df4c | 122 | // destructor |
4403fb69 | 123 | if (AliHLTConfigurationHandler::Instance()) { |
124 | if (AliHLTConfigurationHandler::Instance()->FindConfiguration(fID.Data())!=NULL) { | |
df1e5419 | 125 | // remove the configuration from the handler if it exists |
126 | // but DO NOT remove the clone configuration | |
4403fb69 | 127 | AliHLTConfigurationHandler::Instance()->RemoveConfiguration(this); |
85465857 | 128 | } |
3495cce2 | 129 | } |
130 | if (fArgv != NULL) { | |
131 | if (fArgc>0) { | |
132 | for (int i=0; i<fArgc; i++) { | |
133 | delete[] fArgv[i]; | |
134 | } | |
135 | } | |
136 | delete[] fArgv; | |
137 | fArgv=NULL; | |
138 | } | |
a742f6f8 | 139 | |
140 | vector<AliHLTConfiguration*>::iterator element=fListSources.begin(); | |
141 | while (element!=fListSources.end()) { | |
142 | fListSources.erase(element); | |
143 | element=fListSources.begin(); | |
144 | } | |
3495cce2 | 145 | } |
146 | ||
70ed7d01 | 147 | const char* AliHLTConfiguration::GetName() const |
148 | { | |
c515df4c | 149 | // get name |
52c1c164 | 150 | if (!fID.IsNull()) |
151 | return fID.Data(); | |
3495cce2 | 152 | return TObject::GetName(); |
153 | } | |
154 | ||
155 | AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id) | |
156 | { | |
c515df4c | 157 | // get source by id |
3495cce2 | 158 | AliHLTConfiguration* pSrc=NULL; |
159 | if (id) { | |
160 | // first check the current element | |
d174bfc3 | 161 | if (fListSrcElementIdx>=0 && fListSrcElementIdx<(int)fListSources.size() && |
162 | strcmp(id, (fListSources[fListSrcElementIdx])->GetName())==0) { | |
163 | pSrc=fListSources[fListSrcElementIdx]; | |
3495cce2 | 164 | } else { |
165 | // check the list | |
166 | ||
167 | pSrc=GetFirstSource(); | |
168 | while (pSrc) { | |
169 | if (strcmp(id, pSrc->GetName())==0) | |
170 | break; | |
171 | pSrc=GetNextSource(); | |
172 | } | |
173 | } | |
174 | } | |
175 | return pSrc; | |
176 | } | |
177 | ||
d174bfc3 | 178 | AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() const |
3495cce2 | 179 | { |
c515df4c | 180 | // get first source in the list |
181 | // TODO: iterator class | |
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 | { |
c515df4c | 192 | // get next source |
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 | { |
c515df4c | 205 | // check if all sources are resolved |
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 | { | |
c515df4c | 215 | // invalidate state of all sources |
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 | { |
c515df4c | 238 | // print info |
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 | { |
c515df4c | 272 | // get argument array |
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 | { |
c515df4c | 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 | |
3495cce2 | 298 | int iResult=0; |
d174bfc3 | 299 | fNofSources=0; // indicates that the function was called, there are either n or 0 sources |
300 | fListSources.clear(); | |
4403fb69 | 301 | if (!pHandler) { |
a869209c | 302 | HLTError("configuration handler missing, can not resolve sources"); |
d174bfc3 | 303 | return -EFAULT; |
304 | } | |
52c1c164 | 305 | if (!fStringSources.IsNull()) { |
3495cce2 | 306 | vector<char*> tgtList; |
52c1c164 | 307 | if ((iResult=InterpreteString(fStringSources.Data(), tgtList))>=0) { |
3495cce2 | 308 | fNofSources=tgtList.size(); |
309 | vector<char*>::iterator element=tgtList.begin(); | |
85465857 | 310 | while ((element=tgtList.begin())!=tgtList.end()) { |
4403fb69 | 311 | AliHLTConfiguration* pConf=pHandler->FindConfiguration(*element); |
85465857 | 312 | if (pConf) { |
a742f6f8 | 313 | //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf); |
85465857 | 314 | fListSources.push_back(pConf); |
315 | } else { | |
316 | HLTError("can not find source \"%s\"", (*element)); | |
317 | iResult=-ENOENT; | |
318 | } | |
3495cce2 | 319 | delete[] (*element); |
320 | tgtList.erase(element); | |
321 | } | |
3495cce2 | 322 | } |
323 | } | |
d174bfc3 | 324 | fListSrcElementIdx=-1; |
325 | return iResult<0?iResult:SourcesResolved(); | |
3495cce2 | 326 | } |
327 | ||
328 | int AliHLTConfiguration::ExtractArguments() | |
329 | { | |
c515df4c | 330 | // extract argument list from string |
3495cce2 | 331 | int iResult=0; |
52c1c164 | 332 | if (!fArguments.IsNull()) { |
3495cce2 | 333 | vector<char*> tgtList; |
334 | if ((iResult=InterpreteString(fArguments, tgtList))>=0) { | |
335 | fArgc=tgtList.size(); | |
9ce4bf4a | 336 | //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments); |
3495cce2 | 337 | if (fArgc>0) { |
338 | fArgv = new char*[fArgc]; | |
339 | if (fArgv) { | |
340 | vector<char*>::iterator element=tgtList.begin(); | |
341 | int i=0; | |
342 | while (element!=tgtList.end()) { | |
85465857 | 343 | //HLTDebug("assign arguments %d (%s)", i, *element); |
3495cce2 | 344 | fArgv[i++]=(*element); |
345 | element++; | |
346 | } | |
347 | } else { | |
348 | iResult=-ENOMEM; | |
349 | } | |
350 | } | |
351 | } | |
9ce4bf4a | 352 | } else { |
353 | // there are zero arguments | |
354 | fArgc=0; | |
3495cce2 | 355 | } |
d489ab09 | 356 | if (iResult<0) fArgc=iResult; |
3495cce2 | 357 | return iResult; |
358 | } | |
359 | ||
4b31e06b | 360 | int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList) |
3495cce2 | 361 | { |
c515df4c | 362 | // interprete a string |
3495cce2 | 363 | int iResult=0; |
364 | if (arg) { | |
85465857 | 365 | //HLTDebug("interprete \"%s\"", arg); |
3495cce2 | 366 | int i=0; |
367 | int prec=-1; | |
5f5b708b | 368 | int bQuote=0; |
3495cce2 | 369 | do { |
5f5b708b | 370 | //HLTDebug("%d %x", i, arg[i]); |
371 | if (arg[i]=='\'' && bQuote==0) { | |
372 | bQuote=1; | |
373 | } else if (arg[i]==0 || | |
374 | (arg[i]==' ' && bQuote==0) || | |
375 | (arg[i]=='\'' && bQuote==1)) { | |
376 | bQuote=0; | |
3495cce2 | 377 | if (prec>=0) { |
378 | char* pEntry= new char[i-prec+1]; | |
379 | if (pEntry) { | |
380 | strncpy(pEntry, &arg[prec], i-prec); | |
381 | pEntry[i-prec]=0; // terminate string | |
85465857 | 382 | //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size()); |
3495cce2 | 383 | argList.push_back(pEntry); |
384 | } else | |
385 | iResult=-ENOMEM; | |
386 | prec=-1; | |
387 | } | |
388 | } else if (prec==-1) prec=i; | |
389 | } while (arg[i++]!=0 && iResult>=0); | |
390 | } else { | |
391 | iResult=-EINVAL; | |
392 | } | |
393 | return iResult; | |
394 | } | |
395 | ||
032c5e5e | 396 | int AliHLTConfiguration::ConvertSizeString(const char* strSize) const |
397 | { | |
c515df4c | 398 | // convert a size argument |
032c5e5e | 399 | int size=0; |
400 | if (!strSize) return -1; | |
401 | ||
402 | char* endptr=NULL; | |
403 | size=strtol(strSize, &endptr, 10); | |
404 | if (size>=0) { | |
405 | if (endptr) { | |
406 | if (endptr==strSize) { | |
407 | HLTWarning("ignoring unrecognized buffer size '%s'", strSize); | |
408 | size=-1; | |
409 | } else if (*endptr==0) { | |
410 | // no unit specifier | |
411 | } else if (*endptr=='k') { | |
412 | size*=1014; | |
413 | } else if (*endptr=='M') { | |
414 | size*=1024*1024; | |
415 | } else { | |
416 | HLTWarning("ignoring buffer size of unknown unit '%c'", endptr[0]); | |
417 | } | |
418 | } else { | |
419 | HLTWarning("ignoring negative buffer size specifier '%s'", strSize); | |
420 | size=-1; | |
421 | } | |
422 | } | |
423 | return size; | |
424 | } | |
425 | ||
3495cce2 | 426 | int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList) |
427 | { | |
c515df4c | 428 | // follow dependencies |
3495cce2 | 429 | int iResult=0; |
430 | if (id) { | |
431 | AliHLTConfiguration* pDep=NULL; | |
432 | if ((pDep=GetSource(id))!=NULL) { | |
433 | if (pTgtList) pTgtList->Add(pDep); | |
434 | iResult++; | |
435 | } else { | |
436 | pDep=GetFirstSource(); | |
437 | while (pDep && iResult==0) { | |
438 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
439 | if (pTgtList) pTgtList->AddFirst(pDep); | |
440 | iResult++; | |
441 | } | |
442 | pDep=GetNextSource(); | |
443 | } | |
444 | } | |
445 | } else { | |
446 | iResult=-EINVAL; | |
447 | } | |
448 | return iResult; | |
449 | } | |
450 | ||
3495cce2 | 451 |