]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTConfiguration.cxx
- adaption to gcc >=3
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfiguration.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
7  *          for The ALICE Off-line Project.                               *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // HLT configuration handling                                             //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #if __GNUC__>= 3
25 using namespace std;
26 #endif
27
28 #include <cerrno>
29 #include "AliHLTConfiguration.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTComponentHandler.h"
32 #include <iostream>
33 #include <string>
34
35 ClassImp(AliHLTConfiguration)
36
37 /* the global configuration handler which is used to automatically register the configuration
38  */
39 AliHLTConfigurationHandler* AliHLTConfiguration::fConfigurationHandler=NULL;
40
41 AliHLTConfiguration::AliHLTConfiguration()
42
43   fID=NULL;
44   fComponent=NULL;
45   fStringSources=NULL;
46   fNofSources=-1;
47   fArguments=NULL;
48   fArgc=-1;
49   fArgv=NULL;
50   fListSrcElement=fListSources.begin();
51 }
52
53 AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
54 {
55   fArgc=-1;
56   fArgv=NULL;
57   
58   if (id && component) {
59     fID=id;
60     fComponent=component;
61     fStringSources=sources;
62     fNofSources=-1;
63     fArguments=arguments;
64     fListSrcElement=fListSources.begin();
65     if (fConfigurationHandler) {
66       fConfigurationHandler->RegisterConfiguration(this);
67     } else {
68       HLTError("no configuration handler set, abort registration");
69     }
70   }
71 }
72
73 AliHLTConfiguration::~AliHLTConfiguration()
74 {
75   if (fConfigurationHandler) {
76     if (fConfigurationHandler->FindConfiguration(fID)!=NULL) {
77       fConfigurationHandler->RemoveConfiguration(this);
78     }
79   }
80   if (fArgv != NULL) {
81     if (fArgc>0) {
82       for (int i=0; i<fArgc; i++) {
83         delete[] fArgv[i];
84       }
85     }
86     delete[] fArgv;
87     fArgv=NULL;
88   }
89 }
90
91 int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
92 {
93   int iResult=0;
94   if (fConfigurationHandler!=NULL) {
95     fConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p", fConfigurationHandler);
96   }
97   fConfigurationHandler=pHandler;
98   return iResult;
99 }
100
101 int AliHLTConfiguration::GlobalDeinit()
102 {
103   int iResult=0;
104   fConfigurationHandler=NULL;
105   return iResult;
106 }
107
108 const char* AliHLTConfiguration::GetName() const {
109   if (fID)
110     return fID;
111   return TObject::GetName();
112 }
113
114 AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
115 {
116   AliHLTConfiguration* pSrc=NULL;
117   if (id) {
118     // first check the current element
119     if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
120       pSrc=*fListSrcElement;
121       } else {
122       // check the list
123
124       pSrc=GetFirstSource();
125       while (pSrc) {
126         if (strcmp(id, pSrc->GetName())==0)
127           break;
128         pSrc=GetNextSource();
129       }
130     }
131   }
132   return pSrc;
133 }
134
135 AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
136 {
137   AliHLTConfiguration* pSrc=NULL;
138   if (fNofSources>=0 || ExtractSources()) {
139     fListSrcElement=fListSources.begin();
140     if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
141   } 
142   return pSrc;
143 }
144
145 AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
146 {
147   AliHLTConfiguration* pSrc=NULL;
148   if (fNofSources>0) {
149     if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) 
150       pSrc=*fListSrcElement;
151   } 
152   return pSrc;
153 }
154
155 int AliHLTConfiguration::SourcesResolved(int bAuto) 
156 {
157   int iResult=0;
158   if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) {
159     //HLTDebug("fNofSources=%d", fNofSources);
160     //HLTDebug("list size = %d", fListSources.size());
161     iResult=fNofSources==(int)fListSources.size();
162   }
163   return iResult;
164 }
165
166 int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
167 {
168   int iResult=0;
169   if (pConf) {
170     vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
171     while (element!=fListSources.end()) {
172       if (*element==pConf) {
173         fListSources.erase(element);
174         fListSrcElement=fListSources.end();
175         // there is no need to re-evaluate until there was a new configuration registered
176         // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
177         //InvalidateSources();
178         break;
179       }
180       element++;
181     }
182   } else {
183     iResult=-EINVAL;
184   }
185   return iResult;
186 }
187
188 void AliHLTConfiguration::PrintStatus()
189 {
190   HLTLogKeyword("configuration status");
191   HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
192   if (fComponent) HLTMessage("  - component: \"%s\"", fComponent);
193   else HLTMessage("  - component string invalid");
194   if (fStringSources) HLTMessage("  - sources: \"%s\"", fStringSources);
195   else HLTMessage("  - no sources");
196   if (SourcesResolved(1)<=0)
197     HLTMessage("    there are unresolved sources");
198   AliHLTConfiguration* pSrc=GetFirstSource();
199   while (pSrc) {
200     HLTMessage("    source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
201     pSrc=GetNextSource();
202   }
203 }
204
205 int AliHLTConfiguration::GetArguments(const char*** pArgv)
206 {
207   int iResult=0;
208   if (pArgv) {
209     iResult=fArgc;
210     *pArgv=(const char**)fArgv;
211   } else {
212     iResult=-EINVAL;
213   }
214   return iResult;
215 }
216
217
218 int AliHLTConfiguration::ExtractSources()
219 {
220   int iResult=0;
221   fNofSources=0;
222   if (fStringSources!=NULL) {
223     vector<char*> tgtList;
224     fListSources.clear();
225     if ((iResult=InterpreteString(fStringSources, tgtList))>=0) {
226       fNofSources=tgtList.size();
227       vector<char*>::iterator element=tgtList.begin();
228       while ((element=tgtList.begin())!=tgtList.end()) {
229         if (fConfigurationHandler) {
230           AliHLTConfiguration* pConf=fConfigurationHandler->FindConfiguration(*element);
231           if (pConf) {
232             HLTDebug("source \"%s\" inserted", pConf->GetName());
233             fListSources.push_back(pConf);
234           } else {
235             HLTError("can not find source \"%s\"", (*element));
236             iResult=-ENOENT;
237           }
238         } else if (iResult>=0) {
239           iResult=-EFAULT;
240           HLTFatal("global configuration handler not initialized, can not resolve sources");
241         }
242         delete[] (*element);
243         tgtList.erase(element);
244       }
245       fListSrcElement=fListSources.begin();
246     }
247   }
248   return iResult;
249 }
250
251 int AliHLTConfiguration::ExtractArguments()
252 {
253   int iResult=0;
254   if (fArguments!=NULL) {
255     vector<char*> tgtList;
256     if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
257       fArgc=tgtList.size();
258       //HLTDebug("found %d arguments", fArgc);
259       if (fArgc>0) {
260         fArgv = new char*[fArgc];
261         if (fArgv) {
262           vector<char*>::iterator element=tgtList.begin();
263           int i=0;
264           while (element!=tgtList.end()) {
265             //HLTDebug("assign arguments %d (%s)", i, *element);
266             fArgv[i++]=(*element);
267             element++;
268           }
269         } else {
270           iResult=-ENOMEM;
271         }
272       }
273     }
274   }
275   return iResult;
276 }
277
278 int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
279 {
280   int iResult=0;
281   if (arg) {
282     //HLTDebug("interprete \"%s\"", arg);
283     int i=0;
284     int prec=-1;
285     do {
286       if (arg[i]==0 || arg[i]==' ') {
287         if (prec>=0) {
288           char* pEntry= new char[i-prec+1];
289           if (pEntry) {
290             strncpy(pEntry, &arg[prec], i-prec);
291             pEntry[i-prec]=0; // terminate string
292             //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
293             argList.push_back(pEntry);
294           } else 
295             iResult=-ENOMEM;
296           prec=-1;
297         }
298       } else if (prec==-1) prec=i;
299     } while (arg[i++]!=0 && iResult>=0); 
300   } else {
301     iResult=-EINVAL;
302   }
303   return iResult;
304 }
305
306 int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
307 {
308   int iResult=0;
309   if (id) {
310     AliHLTConfiguration* pDep=NULL;
311     if ((pDep=GetSource(id))!=NULL) {
312       if (pTgtList) pTgtList->Add(pDep);
313       iResult++;
314     } else {
315       pDep=GetFirstSource();
316       while (pDep && iResult==0) {
317         if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
318           if (pTgtList) pTgtList->AddFirst(pDep);
319           iResult++;
320         }
321         pDep=GetNextSource();
322       }
323     }
324   } else {
325     iResult=-EINVAL;
326   }
327   return iResult;
328 }
329
330 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
331
332 ClassImp(AliHLTTask)
333
334 AliHLTTask::AliHLTTask()
335 {
336   fpConfiguration=NULL;
337   fpComponent=NULL;
338   fpBlockDataArray=NULL;
339   fBlockDataArraySize=0;
340   fpDataBuffer=NULL;
341 }
342
343 AliHLTTask::AliHLTTask(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH)
344 {
345   fpConfiguration=NULL;
346   fpComponent=NULL;
347   fpBlockDataArray=NULL;
348   fBlockDataArraySize=0;
349   fpDataBuffer=NULL;
350   Init(fConf, pCH);
351 }
352
353 AliHLTTask::~AliHLTTask()
354 {
355   if (fpComponent) delete fpComponent;
356   fpComponent=NULL;
357   if (fpBlockDataArray) delete[] fpBlockDataArray;
358   fpBlockDataArray=NULL;
359 }
360
361 int AliHLTTask::Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH)
362 {
363   int iResult=0;
364   if (fConf) {
365     fpConfiguration=fConf;
366     if (pCH) {
367       int argc=0;
368       const char** argv=NULL;
369       if ((iResult=fConf->GetArguments(&argv))>=0) {
370         argc=iResult; // just to make it clear
371         iResult=pCH->CreateComponent(fConf->GetComponentID(), NULL, argc, argv, fpComponent);
372         if (fpComponent) {
373         } else {
374           HLTError("can not find component \"%s\"", fConf->GetComponentID());
375         }
376       }
377     }
378   } else {
379     iResult=-EINVAL;
380   }
381   return iResult;
382 }
383
384 const char *AliHLTTask::GetName() const
385 {
386   if (fpConfiguration)
387     return fpConfiguration->GetName();
388   return TObject::GetName();
389 }
390
391 AliHLTConfiguration* AliHLTTask::GetConf() const
392 {
393   return fpConfiguration;
394 }
395
396 AliHLTComponent* AliHLTTask::GetComponent() const
397 {
398   return fpComponent;
399 }
400
401 AliHLTTask* AliHLTTask::FindDependency(const char* id)
402 {
403   AliHLTTask* pTask=NULL;
404   if (id) {
405     pTask=(AliHLTTask*)fListDependencies.FindObject(id);
406   }
407   return pTask;
408 }
409
410 int AliHLTTask::FollowDependency(const char* id, TList* pTgtList)
411 {
412   int iResult=0;
413   if (id) {
414     AliHLTTask* pDep=NULL;
415     if ((pDep=(AliHLTTask*)fListDependencies.FindObject(id))!=NULL) {
416       if (pTgtList) pTgtList->Add(pDep);
417       iResult++;
418     } else {
419       TObjLink* lnk=fListDependencies.FirstLink();
420       while (lnk && iResult==0) {
421         pDep=(AliHLTTask*)lnk->GetObject();
422         if (pDep) {
423           if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
424             if (pTgtList) pTgtList->AddFirst(pDep);
425             iResult++;
426           }
427         } else {
428           iResult=-EFAULT;
429         }
430         lnk=lnk->Next();
431       }
432     }
433   } else {
434     iResult=-EINVAL;
435   }
436   return iResult;
437 }
438
439 void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
440 {
441   HLTLogKeyword("task dependencies");
442   int iResult=0;
443   TList tgtList;
444   if (bFromConfiguration) {
445     if (fpConfiguration)
446       iResult=fpConfiguration->FollowDependency(id, &tgtList);
447     else
448       iResult=-EFAULT;
449   } else
450     iResult=FollowDependency(id, &tgtList);
451   if (iResult>0) {
452     HLTMessage("     task \"%s\": dependency level %d ", GetName(), iResult);
453     TObjLink* lnk=tgtList.FirstLink();
454     int i=iResult;
455     char* pSpace = new char[iResult+1];
456     if (pSpace) {
457       memset(pSpace, 32, iResult);
458       pSpace[i]=0;
459       while (lnk) {
460         TObject* obj=lnk->GetObject();
461         HLTMessage("     %s^-- %s ", &pSpace[i--], obj->GetName());
462         lnk=lnk->Next();
463       }
464       delete [] pSpace;
465     } else {
466       iResult=-ENOMEM;
467     }
468   }
469 }
470
471 /* this function is most likely depricated
472 int AliHLTTask::InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource)
473 {
474   int iResult=0;
475   return iResult;
476 }
477 */
478
479 int AliHLTTask::SetDependency(AliHLTTask* pDep)
480 {
481   int iResult=0;
482   if (pDep) {
483     if (FindDependency(pDep->GetName())==NULL) {
484       fListDependencies.Add(pDep);
485     } else {
486       iResult=-EEXIST;
487     }
488   } else {
489     iResult=-EINVAL;
490   }
491   return iResult;
492 }
493
494 int AliHLTTask::CheckDependencies()
495 {
496   int iResult=0;
497   AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
498   while (pSrc) {
499     if (FindDependency(pSrc->GetName())==NULL) {
500       //HLTDebug("dependency \"%s\" unresolved", pSrc->GetName());
501       iResult++;
502     }
503     pSrc=fpConfiguration->GetNextSource();
504   }
505   return iResult;
506 }
507
508
509 int AliHLTTask::Depends(AliHLTTask* pTask)
510 {
511   int iResult=0;
512   if (pTask) {
513     if (fpConfiguration) {
514       iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL;
515       if (iResult>0) {
516         //HLTDebug("task  \"%s\" depends on \"%s\"", GetName(), pTask->GetName());
517       } else {
518         //HLTDebug("task  \"%s\" independend of \"%s\"", GetName(), pTask->GetName());
519       }
520     } else {
521       iResult=-EFAULT;
522     }
523   } else {
524     iResult=-EINVAL;
525   }
526   return iResult;
527 }
528
529 AliHLTTask* AliHLTTask::FindTarget(const char* id)
530 {
531   AliHLTTask* pTask=NULL;
532   if (id) {
533     pTask=(AliHLTTask*)fListTargets.FindObject(id);
534   }
535   return pTask;
536 }
537
538 int AliHLTTask::SetTarget(AliHLTTask* pTgt)
539 {
540   int iResult=0;
541   if (pTgt) {
542     if (FindTarget(pTgt->GetName())==NULL) {
543       fListTargets.Add(pTgt);
544     } else {
545       iResult=-EEXIST;
546     }
547   } else {
548     iResult=-EINVAL;
549   }
550   return iResult;
551 }
552
553 /* this function is most likely depricated
554 int AliHLTTask::BuildBlockDataArray(AliHLTComponent_BlockData*& pBlockData)
555 {
556   int iResult=0;
557   return iResult;
558 }
559 */
560
561 int AliHLTTask::StartRun()
562 {
563   int iResult=0;
564   int iNofInputDataBlocks=0;
565   AliHLTComponent* pComponent=GetComponent();
566   if (pComponent) {
567     // determine the number of input data blocks provided from the source tasks
568     TObjLink* lnk=fListDependencies.FirstLink();
569     while (lnk && iResult>=0) {
570       AliHLTTask* pSrcTask=(AliHLTTask*)lnk->GetObject();
571       if (pSrcTask) {
572         if ((iResult=pSrcTask->GetNofMatchingDataTypes(this))>0) {
573           iNofInputDataBlocks+=iResult;
574         } else if (iResult==0) {
575           HLTWarning("source task %s (%p) does not provide any matching data type for task %s (%p)", pSrcTask->GetName(), pSrcTask, GetName(), this);
576         } else {
577           HLTError("task %s (%p): error getting matching data types for source task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask);
578           iResult=-EFAULT;
579         }
580       }
581       lnk=lnk->Next();
582     }
583     if (iResult>=0) {
584       if (fpBlockDataArray) {
585         HLTWarning("block data array for task %s (%p) was not cleaned", GetName(), this);
586         delete [] fpBlockDataArray;
587         fpBlockDataArray=NULL;
588         fBlockDataArraySize=0;
589       }
590
591       // component init
592       //iResult=Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
593
594       // allocate internal task varables for bookkeeping aso.
595       fpBlockDataArray=new AliHLTComponent_BlockData[iNofInputDataBlocks];
596       if (fpBlockDataArray) {
597         fBlockDataArraySize=iNofInputDataBlocks;
598       } else {
599         HLTError("memory allocation failed");
600         iResult=-ENOMEM;
601       }
602     }
603   } else {
604     HLTError("task %s (%p) does not have a component", GetName(), this);
605     iResult=-EFAULT;
606   }
607   return iResult;
608 }
609
610 int AliHLTTask::EndRun()
611 {
612   int iResult=0;
613   return iResult;
614 }
615
616 int AliHLTTask::ProcessTask()
617 {
618   int iResult=0;
619   if (fpComponent && fpBlockDataArray) {
620     int iSourceDataBlock=0;
621     int iInputDataVolume=0;
622
623     int iNofInputDataBlocks=0;
624     /* TODO: the assumption of only one output data type per component is the current constraint
625      * later it should be checked how many output blocks of the source component match the input
626      * data types of the consumer component (GetNofMatchingDataBlocks). If one assumes that a
627      * certain output block is always been produced, the initialization could be done in the
628      * StartRun. Otherwise the fpBlockDataArray has to be adapted each time.
629      */
630     iNofInputDataBlocks=fListDependencies.GetSize(); // one block per source
631     // is not been used since the allocation was done in StartRun, but check the size
632     if (iNofInputDataBlocks>fBlockDataArraySize) {
633       HLTError("block data array too small");
634     }
635
636     AliHLTTask* pSrcTask=NULL;
637     TList subscribedTaskList;
638     TObjLink* lnk=fListDependencies.FirstLink();
639
640     // subscribe to all source tasks
641     while (lnk && iResult>=0) {
642       pSrcTask=(AliHLTTask*)lnk->GetObject();
643       if (pSrcTask) {
644         if (pSrcTask->GetNofMatchingDataBlocks(this)<fBlockDataArraySize-iSourceDataBlock) {
645           if ((iResult=pSrcTask->Subscribe(this, &fpBlockDataArray[iSourceDataBlock],fBlockDataArraySize-iSourceDataBlock))>0) {
646             for (int i=0; i<iResult; i++) {
647               iInputDataVolume+=fpBlockDataArray[i+iSourceDataBlock].fSize;
648               // put the source task as many times into the list as it provides data blocks
649               // makes the bookkeeping for the data release easier
650               subscribedTaskList.Add(pSrcTask);
651             }
652             iSourceDataBlock+=iResult;
653             HLTDebug("Task %s (%p) successfully subscribed to %d data blocks of task %s (%p)", GetName(), this, iResult, pSrcTask->GetName(), pSrcTask);
654             iResult=0;
655           } else {
656             HLTError("Task %s (%p): subscription to task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iResult);
657             iResult=-EFAULT;
658           }
659         } else {
660           HLTFatal("Task %s (%p): too little space in data block array for subscription to task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask);
661           iResult=-EFAULT;
662         }
663       } else {
664         HLTFatal("fatal internal error in ROOT list handling");
665         iResult=-EFAULT;
666       }
667       lnk=lnk->Next();
668     }
669
670     // process the event
671     if (iResult>=0) {
672       long unsigned int iConstBase=0;
673       double fInputMultiplier=0;
674       fpComponent->GetOutputDataSize(iConstBase, fInputMultiplier);
675       int iOutputDataSize=int(fInputMultiplier*iInputDataVolume) + iConstBase;
676       AliHLTUInt8_t* pTgtBuffer=fpDataBuffer->GetTargetBuffer(iOutputDataSize);
677       AliHLTComponent_EventData evtData;
678       AliHLTComponent_TriggerData trigData;
679       AliHLTUInt32_t size=iOutputDataSize;
680       AliHLTUInt32_t outputBlockCnt=0;
681       AliHLTComponent_BlockData* outputBlocks=NULL;
682       AliHLTComponent_EventDoneData* edd;
683       if (pTgtBuffer!=NULL || iOutputDataSize==0) {
684         iResult=fpComponent->ProcessEvent(evtData, fpBlockDataArray, trigData, pTgtBuffer, size, outputBlockCnt, outputBlocks, edd);
685       } else {
686       }
687     }
688
689     // now release all buffers which we have subscribed to
690     iSourceDataBlock=0;
691     lnk=subscribedTaskList.FirstLink();
692     while (lnk) {
693       pSrcTask=(AliHLTTask*)lnk->GetObject();
694       if (pSrcTask) {
695         int iTempRes=0;
696         if ((iTempRes=pSrcTask->Release(&fpBlockDataArray[iSourceDataBlock], this))>=0) {
697           HLTDebug("Task %s (%p) successfully released task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask);
698         } else {
699           HLTError("Task %s (%p): realease of task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iTempRes);
700         }
701       } else {
702         HLTFatal("fatal internal error in ROOT list handling");
703         iResult=-EFAULT;
704       }
705       subscribedTaskList.Remove(lnk);
706       lnk=subscribedTaskList.FirstLink();
707       iSourceDataBlock++;
708     }
709     if (subscribedTaskList.GetSize()>0) {
710       HLTError("task %s (%p): could not release all data buffers", GetName(), this);
711     }
712   } else {
713     HLTError("internal failure: task not initialized");
714     iResult=-EFAULT;
715   }
716   return iResult;
717 }
718
719 int AliHLTTask::GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask)
720 {
721   int iResult=0;
722   if (pConsumerTask) {
723     if (fpDataBuffer) {
724       iResult=fpDataBuffer->FindMatchingDataBlocks(pConsumerTask->GetComponent(), NULL);
725     } else {
726       HLTFatal("internal data buffer missing");
727       iResult=-EFAULT;
728     }
729   } else {
730     iResult=-EINVAL;
731   }
732   return iResult;
733 }
734
735 int AliHLTTask::GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask)
736 {
737   int iResult=0;
738   if (pConsumerTask) {
739     AliHLTComponent* pComponent=GetComponent();
740     if (!pComponent) {
741       // init
742     }
743     if (pComponent) {
744       iResult=pComponent->FindMatchingDataTypes(pConsumerTask->GetComponent(), NULL);
745     } else {
746       HLTFatal("task initialization failed");
747       iResult=-EFAULT;
748     }
749   } else {
750     iResult=-EINVAL;
751   }
752   return iResult;
753 }
754
755 int AliHLTTask::Subscribe(const AliHLTTask* pConsumerTask, AliHLTComponent_BlockData* pBlockDesc, int iArraySize)
756 {
757   int iResult=0;
758   if (pConsumerTask) {
759     if (fpDataBuffer) {
760       iResult=fpDataBuffer->Subscribe(pConsumerTask->GetComponent(), pBlockDesc, iArraySize);
761     } else {
762       HLTFatal("internal data buffer missing");
763       iResult=-EFAULT;
764     }
765   } else {
766     iResult=-EINVAL;
767   }
768   return iResult;
769 }
770
771 int AliHLTTask::Release(AliHLTComponent_BlockData* pBlockDesc, const AliHLTTask* pConsumerTask)
772 {
773   int iResult=0;
774   if (pConsumerTask && pBlockDesc) {
775     if (fpDataBuffer) {
776       iResult=fpDataBuffer->Release(pBlockDesc, pConsumerTask->GetComponent());
777     } else {
778       HLTFatal("internal data buffer missing");
779       iResult=-EFAULT;
780     }
781   } else {
782     iResult=-EINVAL;
783   }
784   return iResult;
785 }
786
787 /* this function is most likely depricated
788 int AliHLTTask::ClearSourceBlocks()
789 {
790   int iResult=0;
791   return iResult;
792 }
793 */
794
795 void AliHLTTask::PrintStatus()
796 {
797   HLTLogKeyword("task properties");
798   if (fpComponent) {
799     HLTMessage("     component: %s (%p)", fpComponent->GetComponentID(), fpComponent);
800   } else {
801     HLTMessage("     no component set!");
802   }
803   if (fpConfiguration) {
804     AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
805     while (pSrc) {
806       const char* pQualifier="unresolved";
807       if (FindDependency(pSrc->GetName()))
808         pQualifier="resolved";
809       HLTMessage("     source: %s (%s)", pSrc->GetName(), pQualifier);
810       pSrc=fpConfiguration->GetNextSource();
811     }
812     TObjLink* lnk = fListTargets.FirstLink();
813     while (lnk) {
814       TObject *obj = lnk->GetObject();
815       HLTMessage("     target: %s", obj->GetName());
816       lnk = lnk->Next();
817     }
818   } else {
819     HLTMessage("     task \"%s\" not initialized", GetName());
820   }
821 }
822
823 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
824
825 TList AliHLTConfigurationHandler::fListConfigurations;
826 TList AliHLTConfigurationHandler::fListDynamicConfigurations;
827
828 ClassImp(AliHLTConfigurationHandler)
829
830 AliHLTConfigurationHandler::AliHLTConfigurationHandler()
831 {
832 }
833
834 AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
835 {
836   TObjLink* lnk=fListDynamicConfigurations.FirstLink();
837   while (lnk) {
838     TObject* obj=lnk->GetObject();
839     if (fListConfigurations.FindObject(obj->GetName())==NULL) {
840       HLTDebug("delete dynamic configuration \"%s\"", obj->GetName());
841       delete obj;
842     }
843     lnk=lnk->Next();
844   }
845 }
846
847 int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
848 {
849   int iResult=0;
850   if (pConf) {
851     if (FindConfiguration(pConf->GetName()) == NULL) {
852       fListConfigurations.Add(pConf);
853       //HLTDebug("configuration \"%s\" registered", pConf->GetName());
854
855       // mark all configurations with unresolved dependencies for re-evaluation
856       TObjLink* lnk=fListConfigurations.FirstLink();
857       while (lnk) {
858         AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
859         if (pSrc && pSrc!=pConf && pSrc->SourcesResolved()!=1) {
860           pSrc->InvalidateSources();
861         }
862         lnk=lnk->Next();
863       }
864     } else {
865       iResult=-EEXIST;
866       HLTWarning("configuration \"%s\" already registered", pConf->GetName());
867     }
868   } else {
869     iResult=-EINVAL;
870   }
871   return iResult;
872 }
873
874 int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
875 {
876   int iResult=0;
877   AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
878   if (pConf) {
879     // the configuration will be registered automatically, if this failes the configuration
880     // is missing -> delete it
881     if (FindConfiguration(id)==NULL) {
882       delete pConf;
883       pConf=NULL;
884       iResult=-EEXIST;
885     } else {
886       fListDynamicConfigurations.Add(pConf);
887     }
888   } else {
889     HLTError("system error: object allocation failed");
890     iResult=-ENOMEM;
891   }
892   return iResult;
893 }
894
895 void AliHLTConfigurationHandler::PrintConfigurations()
896 {
897   HLTLogKeyword("configuration listing");
898   HLTMessage("registered configurations:");
899   TObjLink *lnk = fListConfigurations.FirstLink();
900   while (lnk) {
901     TObject *obj = lnk->GetObject();
902     HLTMessage("  %s", obj->GetName());
903     lnk = lnk->Next();
904   }
905 }
906
907 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
908 {
909   int iResult=0;
910   if (id) {
911     AliHLTConfiguration* pConf=NULL;
912     if ((pConf=FindConfiguration(id))!=NULL) {
913       iResult=RemoveConfiguration(pConf);
914     } else {
915       HLTWarning("can not find configuration \"%s\"", id);
916       iResult=-ENOENT;
917     }
918   } else {
919     iResult=-EINVAL;
920   }
921   return iResult;
922 }
923
924 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
925 {
926   int iResult=0;
927   if (pConf) {
928     // remove the configuration from the list
929     fListConfigurations.Remove(pConf);
930     // remove cross links in the remaining configurations
931     TObjLink* lnk=fListConfigurations.FirstLink();
932     while (lnk && iResult>=0) {
933       AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
934       if (pRem) {
935         pRem->InvalidateSource(pConf);
936       } else {
937         iResult=-EFAULT;
938       }
939       lnk=lnk->Next();
940     }
941   }
942   return iResult;
943 }
944
945 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
946 {
947   AliHLTConfiguration* pConf=NULL;
948   if (id) {
949     pConf=(AliHLTConfiguration*)fListConfigurations.FindObject(id); 
950   }
951   return pConf;
952 }
953