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