3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
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 **************************************************************************/
18 /** @file AliHLTSystem.cxx
19 @author Matthias Richter
21 @brief Implementation of HLT module management.
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTSystem.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTComponent.h"
32 #include "AliHLTConfiguration.h"
33 #include "AliHLTConfigurationHandler.h"
34 #include "AliHLTTask.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTSystem)
40 AliHLTSystem::AliHLTSystem()
42 fpComponentHandler(new AliHLTComponentHandler()),
43 fpConfigurationHandler(new AliHLTConfigurationHandler()),
46 if (fpComponentHandler) {
47 AliHLTComponentEnvironment env;
48 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
49 env.fLoggingFunc=AliHLTLogging::Message;
50 fpComponentHandler->SetEnvironment(&env);
52 // init logging function in AliHLTLogging
53 Init(AliHLTLogging::Message);
55 HLTFatal("can not create Component Handler");
57 if (fpConfigurationHandler) {
58 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
60 HLTFatal("can not create Configuration Handler");
64 AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
67 fpComponentHandler(NULL),
68 fpConfigurationHandler(NULL),
71 HLTFatal("copy constructor untested");
74 AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
76 HLTFatal("assignment operator untested");
80 AliHLTSystem::~AliHLTSystem()
83 AliHLTConfiguration::GlobalDeinit();
84 if (fpConfigurationHandler) {
85 delete fpConfigurationHandler;
87 fpConfigurationHandler=NULL;
89 if (fpComponentHandler) {
90 delete fpComponentHandler;
92 fpComponentHandler=NULL;
95 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
105 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
118 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
128 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
132 AliHLTTask* pTask=NULL;
133 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
134 if (pTask->GetConf()!=pConf) {
135 HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
139 } else if (pConf->SourcesResolved(1)!=1) {
140 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
143 pTask=new AliHLTTask(pConf);
149 // check for circular dependencies
150 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
151 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
152 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
153 HLTError("aborted ...");
157 // check whether all dependencies are already in the task list
158 // create the missing ones
159 // this step is an iterative process which calls this function again for the missing
160 // configurations, in order to avoid the currently processed task to be created
161 // again it is added to the list temporarily and removed afterwards
162 // This is of high importance to preserve the order of the tasks. Furthermore, the
163 // InsertTask method has to be used in order to set all the cross links right
164 fTaskList.Add(pTask);
165 AliHLTConfiguration* pDep=pConf->GetFirstSource();
166 while (pDep!=NULL && iResult>=0) {
167 if (FindTask(pDep->GetName())==NULL) {
168 iResult=BuildTaskList(pDep);
170 pDep=pConf->GetNextSource();
172 // remove the temporarily added task
173 fTaskList.Remove(pTask);
175 // insert the task and set the cross-links
177 iResult=InsertTask(pTask);
190 int AliHLTSystem::CleanTaskList()
194 while ((lnk=fTaskList.FirstLink())!=NULL) {
195 fTaskList.Remove(lnk);
196 delete (lnk->GetObject());
201 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
204 TObjLink *lnk = NULL;
205 if ((iResult=pTask->CheckDependencies())>0)
206 lnk=fTaskList.FirstLink();
207 while (lnk && iResult>0) {
208 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
209 //HLTDebug("checking \"%s\"", pCurr->GetName());
210 iResult=pTask->Depends(pCurr);
212 iResult=pTask->SetDependency(pCurr);
213 pCurr->SetTarget(pTask);
214 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
216 if (pCurr->Depends(pTask)) {
217 // circular dependency
218 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
220 } else if ((iResult=pTask->CheckDependencies())>0) {
226 fTaskList.AddAfter(lnk, pTask);
228 fTaskList.AddFirst(pTask);
230 HLTDebug("task \"%s\" inserted", pTask->GetName());
231 } else if (iResult>0) {
232 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
238 AliHLTTask* AliHLTSystem::FindTask(const char* id)
240 AliHLTTask* pTask=NULL;
242 pTask=(AliHLTTask*)fTaskList.FindObject(id);
247 void AliHLTSystem::PrintTaskList()
249 HLTLogKeyword("task list");
250 TObjLink *lnk = NULL;
251 HLTMessage("Task List");
252 lnk=fTaskList.FirstLink();
254 TObject* obj=lnk->GetObject();
256 HLTMessage(" %s - status:", obj->GetName());
257 AliHLTTask* pTask=(AliHLTTask*)obj;
258 pTask->PrintStatus();
265 void AliHLTSystem::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) {
267 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
268 for ( unsigned i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
269 if (dt.fID[i]!=0) msg+=dt.fID[i];
273 for ( unsigned i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
274 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
278 HLTMessage(msg.Data());
281 int AliHLTSystem::Run(Int_t iNofEvents)
284 if ((iResult=StartTasks())>=0) {
285 for (int i=0; i<iNofEvents && iResult>=0; i++) {
286 iResult=ProcessTasks(i);
288 HLTInfo("Event %d successfully finished (%d)", i, iResult);
291 HLTError("Processing of event %d failed (%d)", i, iResult);
292 // TODO: define different running modes to either ignore errors in
293 // event processing or not
300 HLTError("can not start task list");
305 int AliHLTSystem::StartTasks()
308 TObjLink *lnk=fTaskList.FirstLink();
309 while (lnk && iResult>=0) {
310 TObject* obj=lnk->GetObject();
312 AliHLTTask* pTask=(AliHLTTask*)obj;
313 iResult=pTask->StartRun();
323 int AliHLTSystem::ProcessTasks(Int_t eventNo)
326 HLTDebug("processing event no %d", eventNo);
327 TObjLink *lnk=fTaskList.FirstLink();
328 while (lnk && iResult>=0) {
329 TObject* obj=lnk->GetObject();
331 AliHLTTask* pTask=(AliHLTTask*)obj;
332 iResult=pTask->ProcessTask();
340 int AliHLTSystem::StopTasks()
343 TObjLink *lnk=fTaskList.FirstLink();
344 while (lnk && iResult>=0) {
345 TObject* obj=lnk->GetObject();
347 AliHLTTask* pTask=(AliHLTTask*)obj;
348 iResult=pTask->EndRun();